Question about ereg_replace and urlencode...

From: Date: Tue, 02 Oct 2007 14:55:15 +0000
Subject: Question about ereg_replace and urlencode...
Groups: php.general 
Request: Send a blank email to php-general+get-262640@lists.php.net to get a copy of this message
Hello! i am trying to make links clickable on a page. I would like to urlencode the URL so that it is well passed to a redirect.php file, which would do somethings and then also do a meta http refresh I am trying to use a function like the following, but it doesn't work. I would like to apply urlencode on the link that is there in $str, so that i have the link to redirect.php?url=<<urlencoded str>> With the following, "1" gets hardcoded in my link! How do i urlencode it please? Any thoughts would help Regards Venky <?php $str='blah blah http://www.someserver.com/indexn12.asp?main_variable=EDITS&amp;file_name=edit3%2Etxt&amp;counter_img=3 blah blah'; function b_make_clickable ($str) { $str = eregi_replace('(((f|ht){1}tp://)[-a-zA-Z0-9@:%_+.~#?&//=]+)', '<a href="http://www.myserver.com/redirect.php?url=' . urlencode(1) . '" target="_blank">\1</a>', $str); $str = eregi_replace('([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_+.~#?&//=]+)', '\1<a href="http://www.myserver.com/redirect.php?url=http://' . urlencode(2) . '" target="_blank">\2</a>', $str); $str = eregi_replace('([_.0-9a-z-]+@([0-9a-z][0-9a-z-]+.)+[a-z]{2,3})','<a href="mailto:\1">\1</a>', $str); return $str; } ?>

« previous php.general (#262640) next »