从字符串中删除:字符

时间:2012-09-23 22:38:36

标签: php

我抓取网络获取标题

$title = strip_tags($link1->plaintext);

但结果中有Data Mining&#58 Concepts and Techniques

之类的结果

如何删除&#58?谢谢

2 个答案:

答案 0 :(得分:2)

问题是:对于冒号是character entity reference,但是您的示例未正确终止(缺少结尾分号)。您可以使用以下(相当幼稚的)正则表达式修复未终止的引用:

$broken = "Data Mining&#58 Concepts and Techniques";
$fixed = preg_replace('/(&#x?[a-e0-9]+)\b/i', '$1;', $broken);

然后您可以使用html_entity_decode

echo html_entity_decode($fixed); // Data Mining: Concepts and Techniques

答案 1 :(得分:0)

$title = str_replace("&#58", "", strip_tags($link1->plaintext));

相关问题