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?
Regex or something else for links?
Moderator: General Moderators
- redhair
- Forum Contributor
- Posts: 300
- Joined: Fri May 30, 2003 4:36 pm
- Location: 53.23N-6.57E
- Contact:
Re: Regex or something else for links?
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)
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
Ok. Great. Now that you've done that:
Is what you're really looking for. So, how about you buy me a pint now? 
Before you read on: read the tutorial above
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>";
?>