从字符串中删除大于号的符号?

时间:2015-08-11 08:21:28

标签: php

我有这样的文字:

<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。所以无论如何都要移除这个&#34;&gt;&#34;符号?

4 个答案:

答案 0 :(得分:3)

您可以使用 DB db = client.getDB("$external"); CommandResult result = db.command(new BasicDBObject("createUser",userName).append("roles", Collections.singletonList(new BasicDBObject("role", "dbOwner").append("db", "CMRepWs_Username")))); result.throwOnError(); 功能

preg_replace()

它会在行首开始删除$str= preg_replace('/^\>/m', '', $str);

答案 1 :(得分:1)

简单的解决方案 -

$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;

答案 2 :(得分:0)

几个小时,我在想为什么我不能删除更大和更小的字符串,这应该很容易,然后我发布,html实体代码是不同的。

$string= str_replace('&gt;', '', $string);
$string= str_replace('&lt;', '', $string);



&gt;     : > (greater-than)
&lt;     : < (less-than)
&amp;    : & (ampersand)
&raquo;  : » (right angle quote marks)
&eacute; : é (e acute)

答案 3 :(得分:0)

另一个简单的选择是使用Trim并将符号作为第二个参数(Charlist)传递,如下所示:

trim($string, " <>");

简单但有效!