dongtaihui5131 2010-02-08 10:50
浏览 12

PHP函数不能与String对象一起使用,但可以手动键入它

I'm trying to strip tags from a text output coming from an object. The problem is, that I can't. If I type it manually like "<p>http://www.mylink.com</p>", it works fine! When doing echo $item->text; it gives me the same string "<p>http://www.mylink.com</p>"; Doing var_dump or even gettype, gives me a string(). So, I'm sure its a string, but it's not acting like it, I tried several functions preg_replace, preg_match, strip_Tags, none worked. How can I solve this situation, how to debug it ?


 $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;
  • 写回答

2条回答 默认 最新

  • douci1918 2010-02-08 11:00
    关注

    Try the following

    $text = $item->introtext;
    $newText = strip_tags($text);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 r包runway详细安装教程
  • ¥15 Html中读取Json文件中数据并制作表格
  • ¥15 谁有RH342练习环境
  • ¥15 STM32F407 DMA中断问题
  • ¥15 uniapp连接阿里云无法发布消息和订阅
  • ¥25 麦当劳点餐系统代码纠错
  • ¥15 轮班监督委员会问题。
  • ¥20 关于变压器的具体案例分析
  • ¥15 生成的QRCode圖片加上下載按鈕
  • ¥15 板材切割优化算法,数学建模,python,lingo