php preg_replace find&;mdash;替换为—;
我猜&和;把我的搜索搞砸了。当我只搜索mdash时,它会找到它,但当然不会替换∨围绕着它 这是我尝试过的,我认为应该有效的方法(我也尝试过很多其他方法,但是…): 我已经在谷歌上搜索过了,所以没有结果,所以现在我只是在拔头发 谢谢 增加: 我从url获得$description:?description=clay%252520%252526mdash%25253B%252520和%252520 Veronicaphp preg_replace find&;mdash;替换为—;,php,regex,Php,Regex,我猜&和;把我的搜索搞砸了。当我只搜索mdash时,它会找到它,但当然不会替换∨围绕着它 这是我尝试过的,我认为应该有效的方法(我也尝试过很多其他方法,但是…): 我已经在谷歌上搜索过了,所以没有结果,所以现在我只是在拔头发 谢谢 增加: 我从url获得$description:?description=clay%252520%252526mdash%25253B%252520和%252520 Veronica $description = $_GET["description"]; $d
$description = $_GET["description"];
$description=rawurldecode($description);
$description=rawurldecode($description);
$description=htmlentities($description);
$description=stripslashes($description);
$description = preg_replace("/\&mdash\;/", "—", $description);
echo $decription;
产生:
粘土&粉煤灰;和维罗妮卡
(不带“&mdash之间的“”)因为它在此处转换为mdash,所以不应使用
preg\u replace
替换常量字符串。只需使用str\u replace
即可
$description = str_replace("—","—", $description);
tim@roflcopter/tmp$cat>blah.php
您的&实际上是html实体&代码>所以你需要替换它
$description =str_replace("—", "—", $description);
是另一种应该可以很好工作的方法,只需在终端中快速试用即可。str_repalce()将是faster@Dagon这就是我开始的地方,$message=str_replace(“—”,“-”,$message);,它也不起作用。为Mem工作必须是我的输入,嗯,编辑问题。。。
tim@roflcopter /tmp $ cat >blah.php
<?php
$description = "there. &MDASH; with David";
$description = preg_replace("/\&mdash\;/i", "—", $description);
echo $description;
tim@roflcopter /tmp $ php blah.php
there. — with David
$description =str_replace("&mdash;", "—", $description);