Page 1 of 1

Regex or something else for links?

Posted: Thu Jun 05, 2003 12:13 pm
by InternetX
Hi!

Have anyone a regex or something else to make links in a text automatically
to a http link? As example an user write:

http://www.domain.com

Then the php script make a link with this:

<a href="www.domain.com">www.domain.com</a>

Or is this not possible?


Edit:
This function is in this board software, too.
How works it?

Re: Regex or something else for links?

Posted: Thu Jun 05, 2003 12:53 pm
by redhair
InternetX wrote:
http://www.domain.com
intresting....a link.. hey did you do that? You just typed http://www.domain.com ...and it turned into a link :?:

go read this:
http://www.php.net/manual/en/function.preg-match.php
About a function that could check for 'www.' in your variable.
read also:
http://www.php.net/manual/en/function.preg-replace.php
How you can manipulate your variable...(make a link out of it)

Posted: Thu Jun 05, 2003 1:13 pm
by InternetX
I will look... thanks...

Posted: Thu Jun 05, 2003 1:16 pm
by patrikG
A nice bit of googling yielded a nice little tutorial which I think is what you are looking for.

Before you read on: read the tutorial above :P


Ok. Great. Now that you've done that:

Code: Select all

<?php
$message='Bobs is neat http://www.bob.com as heck, the good Bob http://www.bob.com Bobs Bob drinks Guinness.';
echo "<xmp>$message</xmp>";
$message=preg_replace('/(www\.\b)+/i','http://\1',$message);

echo "<xmp>$message</xmp>";
?>
Is what you're really looking for. So, how about you buy me a pint now? :P

Posted: Thu Jun 05, 2003 2:08 pm
by InternetX
Thanks *s*