Re: Question about ereg_replace and urlencode...
| From: | Venkatesh M. S. | Date: | Tue, 02 Oct 2007 15:11:19 +0000 |
| Subject: | Re: Question about ereg_replace and urlencode... | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-262642@lists.php.net to get a copy of this message | ||
Many thanks Stut
The problem is that the rest of the $str is actually a big post from a
blog, which will have many other text and info apart from the URL, and
i don't want to urlencode everything in there!
Venky
On 02/10/2007, Stut <stuttle@gmail.com> wrote:
> 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/
>