Page 1 of 1

please help : tricky "$" replacement problem in a

Posted: Wed Oct 22, 2003 9:08 pm
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:

Posted: Wed Oct 22, 2003 9:18 pm
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
?>

Posted: Thu Oct 23, 2003 11:03 am
by sona
hi volka, thanks :)