我有这样的文本:
<p>Mix together the mustard, honey, lemon zest and juice, remaining olive oil and season.> Pour over the quinoa and mix together.Add the toasted pumpkin seeds, basil leaves, chopped avocado, peas and scatter over rocket. Mix gently and serve immediately.</p>
>
<p>Cook the peas for 2 minutes in boiling water, refresh under cold running water and drain.</p>
>
我的文本也有p标签,所以我不能使用str_replace .So无论如何要删除这个">"符号?
可以使用preg_replace()
函数
$str= preg_replace('/^'>/m', '', $str);
它将删除行开头的>
。
几个小时,我在想为什么我不能删除更大和更小的字符串,它应该很容易,然后我发布,html实体代码是不同的。
$string= str_replace('>', '', $string);
$string= str_replace('<', '', $string);
> : > (greater-than)
< : < (less-than)
& : & (ampersand)
» : » (right angle quote marks)
é : é (e acute)
简单解决方案-
$str = "<p>Mix together the mustard, honey, lemon zest and juice, remaining olive oil and season.> Pour over the quinoa and mix together.Add the toasted pumpkin seeds, basil leaves, chopped avocado, peas and scatter over rocket. Mix gently and serve immediately.</p>
>
<p>Cook the peas for 2 minutes in boiling water, refresh under cold running water and drain.</p>
>";
echo $str;
$str= str_replace('>', '', $str);
$str = str_replace('<p', '<p>', $str);
echo $str;
另一个简单的选择是使用Trim并将符号作为第二个参数(charlist)传递,如下所示:
trim($string, " <>");
简单但有效!