PHP functions wont work with String object, but works with it typed manually

Posted by heldrida on Stack Overflow See other posts from Stack Overflow or by heldrida
Published on 2010-02-08T10:50:02Z Indexed on 2010/03/23 10:03 UTC
Read the original article Hit count: 310

Filed under:
|
|
|

Hi,

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;

© Stack Overflow or respective owner

Related posts about php

Related posts about functions