【发布时间】:2021-11-09 15:30:46
【问题描述】:
我有一个这样的字符串
$content="#Love #Lovestories #Lovewalapyar";
想让这些主题标签可点击。
我有一个数组。
$tags=
(
[0] => stdClass Object
(
[TOPIC_ID] => 132
[TOPIC_NAME] => Love
[TOPIC_URL] => http://local/topic/132/love
)
[1] => stdClass Object
(
[TOPIC_ID] => 3347
[TOPIC_NAME] => LoveStories
[TOPIC_URL] => http://local/topic/3347/lovestories
)
[2] => stdClass Object
(
[TOPIC_ID] => 43447
[TOPIC_NAME] => lovewalapyar
[TOPIC_URL] => http://local/topic/43447/lovewalapyar
)
);
Using this to make hashtags clickable.
foreach($tags as $tag){
$content=str_ireplace('#'.$tag->TOPIC_NAME, '<a href="'.$tag->TOPIC_URL.'" title="'.htmlentities($tag->TOPIC_NAME).'">#'.$tag->TOPIC_NAME.'</a>', $content);
}
得到这个: 它只替换 love 而不是其他字符串。
尝试替换/使这些主题标签可点击。
任何帮助将不胜感激。
【问题讨论】:
标签: php string replace str-replace