用开始和结束 html 标签替换引号
Replace quotes with open and close html tags
我有以下字符串:
'something can go here' and there some more text 'then some more here'
我想成为:
<pre>something can go here</pre> and there some more text <pre>then some more here</pre>
我知道你能做到:
str_replace($replace, $with, $from);
但是由于两端都是同一个符号,所以不会起作用,解决这个问题的最佳方法是什么?
这应该适合你:
(只需使用 preg_replace()
然后您可以根据需要替换引号)
<?php
$str = "'something can go here' and there some more text 'then some more here'";
echo $str = preg_replace("/'(.*?)'/", "<pre></pre>", $str);
?>
输出:
<pre>something can go here</pre> and there some more text <pre>then some more here</pre>
//^^^ ^^^^^^ ^^^^^ ^^^^^^
我有以下字符串:
'something can go here' and there some more text 'then some more here'
我想成为:
<pre>something can go here</pre> and there some more text <pre>then some more here</pre>
我知道你能做到:
str_replace($replace, $with, $from);
但是由于两端都是同一个符号,所以不会起作用,解决这个问题的最佳方法是什么?
这应该适合你:
(只需使用 preg_replace()
然后您可以根据需要替换引号)
<?php
$str = "'something can go here' and there some more text 'then some more here'";
echo $str = preg_replace("/'(.*?)'/", "<pre></pre>", $str);
?>
输出:
<pre>something can go here</pre> and there some more text <pre>then some more here</pre>
//^^^ ^^^^^^ ^^^^^ ^^^^^^