【发布时间】:2010-02-08 10:50:02
【问题描述】:
我正在尝试从来自对象的文本输出中去除标签。问题是,我做不到。如果我像"<p>http://www.mylink.com</p>" 一样手动输入它,它工作正常!执行echo $item->text; 时,它给了我相同的字符串"<p>http://www.mylink.com</p>"; 执行var_dump 甚至gettype,给了我一个string()。所以,我确定它是一个字符串,但它不像它,我尝试了几个函数preg_replace,preg_match,strip_Tags,没有一个工作。我该如何解决这种情况,如何调试?
$search = array("<p>", "</p>");
$switch = array("foo", "baa");
//works just fine, when used
$text = "<p>http://www.mylink.com</p>";
//it's a string for sure!
var_dump($item->introtext);
$text = $item->introtext;
//doesn't work
$text = str_replace($search, $switch, $text);
$text = strip_tags($text, "<p>");
//doesn't work either.
$matches = array();
$pattern = '/<p>(.*)<\/p>/';
preg_match($pattern, $text, $matches);
//gives me the following output: <p>http://www.omeulink.com</p>
echo $text;
【问题讨论】:
标签: php string object function