用逗号替换字符串或用 preg_replace 不替换字符串
我有一个具有以下值格式的字符串:
$str = "Apple, Orange, Computer-Hardware, preg_replace, 50k";
或
$str = "Computer";
如何使用 preg_replace 将其转换为:
$str = "<a href='p.php?s=Apple'>Apple</a>, <a href='p.php?s=Orange'>Orange</a>,
<a href='p.php?s=Computer-Hardware'>Computer-Hardware</a>, <a href='p.php?s=preg_replace'>preg_replace</a>, <a href='p.php?s=50k'>50k</a>";
$str = "<a href='p.php?s=Computer'>Computer</a>";
I have a string with this value format:
$str = "Apple, Orange, Computer-Hardware, preg_replace, 50k";
or
$str = "Computer";
How can I convert it with preg_replace to:
$str = "<a href='p.php?s=Apple'>Apple</a>, <a href='p.php?s=Orange'>Orange</a>,
<a href='p.php?s=Computer-Hardware'>Computer-Hardware</a>, <a href='p.php?s=preg_replace'>preg_replace</a>, <a href='p.php?s=50k'>50k</a>";
$str = "<a href='p.php?s=Computer'>Computer</a>";
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试一下:
输出:
Have a try with:
output: