Automatic parse...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
fatalcure
Forum Contributor
Posts: 141
Joined: Thu Jul 04, 2002 12:57 pm
Contact:

Automatic parse...

Post 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
User avatar
QWERTY
Forum Newbie
Posts: 20
Joined: Sat Jun 29, 2002 10:57 am
Location: Slovenia

...

Post 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...
fatalcure
Forum Contributor
Posts: 141
Joined: Thu Jul 04, 2002 12:57 pm
Contact:

Post 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?
User avatar
cheatboy00
Forum Contributor
Posts: 151
Joined: Sat Jun 29, 2002 10:36 am
Location: canada
Contact:

Re: ...

Post 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....
User avatar
QWERTY
Forum Newbie
Posts: 20
Joined: Sat Jun 29, 2002 10:57 am
Location: Slovenia

...

Post 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...
Post Reply