Page 1 of 1

Automatic parse...

Posted: Sun Jul 07, 2002 1:07 pm
by fatalcure
I have a textarea field where users can enter anything they want, similar to a messageboard. What i want to know is:

1. How can I automatically parse if someone enters a URL like so: http://www.a_site.com/ into a clickable LINK
2. Same as above, but with an email.

Thanks

...

Posted: Sun Jul 07, 2002 3:33 pm
by QWERTY

Code: Select all

$text = preg_replace ("/(ftp|http|https):\/\/(&#1111;a-z0-9~#%@&:;=!',_crl\(\)\?\/\.\-\+\&#1111;\]\|\*\$\^\&#123;\&#125;]+)/i", "<a href="\\1://\\2" target="_blank">\\1://\\2</a>", $text); 

$text = preg_replace ("/(&#1111;\s|"])(&#1111;\w|\.|\-|_]+)@(&#1111;\w||\-|_]+)\.(&#1111;\w|\.|\-|_]+)/i", "\\1<a href="mailto:\\2@\\3.\\4">\\2@\\3.\\4</a>", $text);
Replace $text with variable with text in it...

Posted: Sun Jul 07, 2002 5:13 pm
by fatalcure
ahh sweet, thanks a lot :)

and as for the smileys, replacing them would be like this?

Code: Select all

$text = str_replace(":)", "<img src='images/smile.gif'>", $text);
$text = str_replace(":D", "<img src='images/grin.gif'>", $text);
...
...
etc.
correct?

Re: ...

Posted: Sun Jul 07, 2002 7:18 pm
by cheatboy00
QWERTY wrote:

Code: Select all

$text = preg_replace ("/(ftp|http|https):\/\/(&#1111;a-z0-9~#%@&:;=!',_crl\(\)\?\/\.\-\+\&#1111;\]\|\*\$\^\&#123;\&#125;]+)/i", "<a href="\\1://\\2" target="_blank">\\1://\\2</a>", $text); 

$text = preg_replace ("/(&#1111;\s|"])(&#1111;\w|\.|\-|_]+)@(&#1111;\w||\-|_]+)\.(&#1111;\w|\.|\-|_]+)/i", "\\1<a href="mailto:\\2@\\3.\\4">\\2@\\3.\\4</a>", $text);
Replace $text with variable with text in it...
holy <span style='color:blue' title='I&#39;m naughty, are you naughty?'>smurf</span>, what the hell is that.... what do things liek this....

/([\s|"])([\w|\.|\-|_]+)@([\w||\-|_]+)\.([\w|\.|\-|_]+)/i

mean, i understand the bit with the @ but whats with all the crazy slashes and stuff....

...

Posted: Sun Jul 07, 2002 9:25 pm
by QWERTY
:) Check this out:
http://www.evolt.org/article/rating/20/22700/index.html

It's the explanation of that "mess"...:D
It could probably be shorter, but hey, I'm still learning...

Fatalcure, yes, that is correct...