开发者

PHP/MySQL Link Each Word

开发者 https://www.devze.com 2023-01-20 02:40 出处:网络
I have a PHP scri开发者_高级运维pt that pulls keywords from a MySQL database and I need help with figuring out how to link each word.

I have a PHP scri开发者_高级运维pt that pulls keywords from a MySQL database and I need help with figuring out how to link each word.

An example MySQL entry: cow moo white black

Need to output in link form:

<a href=word.php?word=cow>cow</a> <a href=word.php?word=moo>moo</a>, etc.

Thank you


Try this:

$output = "";
$mysql_str = "cow moo white black";
$keywords = explode(" ", $mysql_str);

foreach ($keywords as $keyword) {
  $output .= "<a href=\"word.php?word=".$keyword."\">".$keyword."</a> ";
}

echo $output;


If $row["entry"] is the entry, then as follows:

   $fieldArray = split(" ", $row["entry"]);

    foreach($fieldArray as $item) {
      echo "<a href=\"word.php?word=" . $item . "\">" . $item . "</a>";
    }
0

精彩评论

暂无评论...
验证码 换一张
取 消