【问题标题】:How to split the title in the php string to create the html tags link for the post如何在 php 字符串中拆分标题以创建帖子的 html 标签链接
【发布时间】:2018-07-20 23:38:20
【问题描述】:

我想用$title创建动态网址。

$title = "google facebook pikachu";
$tags = $title;
$link = "https://example.com/?";

// Output should be like this

<a href="https://example.com/?google">google</a>
<a href="https://example.com/?google">facebook</a> 
<a href="https://example.com/?pikachu">pikachu</a>

谢谢大家!

【问题讨论】:

标签: php string hyperlink split tags


【解决方案1】:
$title = "google facebook pikachu";
$tags = $title;
$link = "https://example.com/?";

foreach( explode(' ', $title ) as $target ){
   echo "<a href='".$link.$target."'>".$target."</a> ";
}

【讨论】:

  • 我第一次加入这个论坛,我真的很惊讶帮助非常快速和准确。非常感谢 !
【解决方案2】:

您可以使用explode() 函数来创建链接数组。

$titles = explode(" " , $title);

foreach ($titles as $title) {
  echo '<a href='.$link.$title.'>'.$title.'</a><br />';
}

【讨论】:

  • 我第一次加入这个论坛,我真的很惊讶帮助非常快速和准确。非常感谢!
猜你喜欢
  • 1970-01-01
  • 2015-12-27
  • 1970-01-01
  • 1970-01-01
  • 2023-03-30
  • 1970-01-01
  • 2015-06-08
  • 2012-11-07
  • 1970-01-01
相关资源
最近更新 更多