Forum Moderators: coopster

Message Too Old, No Replies

Make link with a phrase

         

dexten

8:00 pm on Aug 24, 2006 (gmt 0)

10+ Year Member



I would like to have some help for this:

There is any phrase like "Some text, here, #*$!, yyy aaaa"

I need to separate the words and make links, like:
<a href='Some'>Some</a> <a href='text'>text</a> <a href='here'>here</a>

Someone know any topic that explain how to do that?

Regards

eelixduppy

9:28 pm on Aug 24, 2006 (gmt 0)



Welcome to WebmasterWorld!

Something like this:


$pattern = "/([^\s\w]*)/i";
$string = "Some text, here, #*$!, yyy aaaa";
$new_str = preg_replace($pattern,'',$string);
$words = explode(' ',$new_str);
$count = count($words);
for($i = 0;$i < $count; $i++) {
echo '<a href="'.$words[$i].'">'.$words[$i].'</a><br />';
}

*This is untested. You will have to mess around with it*

Good luck!