Reputation:
Let's say I have this block of text in a string:
hello guys good man
I would like to convert this string (using PHP) to something like this:
<a href="http://www.dumbsearch.com/now/searchcompleted.php?q=hello">hello</a> <a href="http://www.dumbsearch.com/now/searchcompleted.php?q=guys">guys</a> <a href="http://www.dumbsearch.com/now/searchcompleted.php?q=good">good</a> <a href="http://www.dumbsearch.com/now/searchcompleted.php?q=man">man</a>
Thanks a heck in advance! :)
Would this envolve some regular expressions or something?
Upvotes: 0
Views: 153
Reputation: 846
you can just use explode then use foreach.
<?php
$a="hello guys good man";
$a=explode(' ',$a);
foreach($a as $linkit)
{
echo '<a href="http://www.dumbsearch.com/now/searchcompleted.php?q='.$linkit.'">'.$linkit.'</a><br>';
}
?>
Hope it helps Abnab
Upvotes: -1
Reputation: 16989
Try something like this:
<?
$str = "hello guys good man";
$arr = explode(' ', $str);
foreach($arr as $value){
echo '<a href="http://www.dumbsearch.com/now/searchcompleted.php?q='.$value.'">'.$value.'</a>';
}
?>
Upvotes: 2