please help : tricky "$" replacement problem in a

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sona
Forum Newbie
Posts: 8
Joined: Sun Oct 19, 2003 4:07 am

please help : tricky "$" replacement problem in a

Post by sona »

I want any $ entered in text area to be converted to "dollars" on submission
However if there is any hyperlink containing $ like ( http: // localhost/index.php?subject=view&msg=$msg23 )
I want that $ to be preserved otherwise the link wont work.

Everytime I try with eregi and all that both gets converted to dollar

Code: Select all

$message= str_replace( "$", "dollar",$message);
$message = eregi_replace("(([hH][tT][tT][pP]://)(www\.)?([a-z0-9_-]+(\.[a-z0-9_-]+)+)(/[^/ \n\r]*)*)","<a href=\\1 		target=new><img src =0smli-hand.gif border=0></a>",$message);
any help will be highly appreciated - best wishes and regards

ps : the subject of the htread was' please help : tricky "$" replacement problem in a string' however the word 'string' is getting filtered out :cry:
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

might be easier if you first convert all $ within a link to their url-encoded counterpart
$ <-> %24

Code: Select all

<?php
echo urlencode('$');
echo urldecode('%24'); // no need to do this yourself, $_GET/$_POST are decoded automagically
?>
sona
Forum Newbie
Posts: 8
Joined: Sun Oct 19, 2003 4:07 am

Post by sona »

hi volka, thanks :)
Post Reply