Re: Question about ereg_replace and urlencode...
| From: | Stut | Date: | Tue, 02 Oct 2007 15:08:03 +0000 |
| Subject: | Re: Question about ereg_replace and urlencode... | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-262641@lists.php.net to get a copy of this message | ||
Venkatesh M. S. wrote:
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&file_name=edit3%2Etxt&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; } ?>That would be the bit where you use urlencode(1) to put the URL into the URL. I think you want urlencode($str) instead. -Stut -- http://stut.net/