The purpose of the code is to isolate the single words that appear before commas, and create hyperlinks out of them. This is probably a sloppy way of doing it. But it seems to be pretty close. Can you see where I'm wrong?
$string = "I like football, but I also like baseball, basketball and swimming.";
preg_match_all('/(\w+),/m', $string, $matches, PREG_SET_ORDER);
$s = 0;
foreach($matches as $name)
{
array($name) ;
$name = str_replace(",","",$name);
$new_string = str_replace($name[$s], "<a href=\"http://www.domain.com/$name[$s]\">$name[$s]</a>", "$string");
echo"<pre>";
print_r($name);
echo"</pre>";
$s++;
}
echo ("<br>$new_string");
The output is:
Array
(
[0] => football
[1] => football
)
Array
(
[0] => baseball
[1] => baseball
)
I like football, but I also like [URL=http://www.domain.com/baseball]baseball[/URL], basketball and swimming.
I want it to hyperlink football, too.
Any ideas?
Thanks!
Greg