Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I give up.... ereg_replace to preg_replace 1

Status
Not open for further replies.

eraH

MIS
Dec 1, 2003
106
NZ
I finally worked out how to use ereg_replace to remove a character, only to find that I shouldn't use ereg_replace because it's been replaced by preg_replace.
Code:
$row->Note = ereg_replace(chr(188),"",$row->Note);

I can't for the life of me, figure out how to convert the above line to preg_replace
Code:
$row->Note = preg_replace("\188","",$row->Note);
No ending delimiter '' found

Code:
$row->Note = preg_replace("\chr(188)\","",$row->Note);
Is a blank screen.

I've tried a couple of variations, I also managed to get it working at some stage except that it didn't do anything :(
 
Would this be acceptable for the purpose?
[tt] $row->Note = preg_replace('/'.chr(188).'/','',$row->Note);[/tt]
 
is there any reason why you are using preg_replace or ereg_replace for this? would not the easier and quicker str_replace be better?


Also I believe that character code 188 is the single character representation of 1/4. it seems a bit odd to replace this with a zero width string - effective deletion Why do you want to do this? if it is an issue with browser display, have you considered using the html entity ¼ instead?
 
Fantastic tjusi, a star for you!

jpadie, it's because I'm getting the data for the website from a database and there are 1/4 symbols in the tables. Not sure why, this is something I've inherited.
If there is a better/proper way of doing this,then let me know. It doesn't seem to make any difference to the display other than removing the odd characters from the HTML.
 
perhaps there should be those symbols? or perhaps you are using the wrong character set (or the wrong character set was used in the input of the data.

from the php perspective: str_replace is better than preg_replace for these type of simple substitutions as there is no requirement to load the PCRE engine.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top