views:

51

answers:

4

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&lt;/p&gt;", it works fine! When doing echo $item->text; it gives me the same string "<p>http://www.mylink.com&lt;/p&gt;"; 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&lt;/p&gt;"; 

 //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&lt;/p&gt;
 echo $text;
A: 

A pastebin with same code:

http://codepad.org/BN1URZbZ

Jahmaica
Don't answer to your own questions with something that should be put into the original question (edited in) instead.
amn
Forget it! I've redone this script (it was done by a friend), and it works! So this can be in the entry point...theres something wrong
Jahmaica
A: 

I've redone this and works fine! This script was done by a friend and it probably has something wrong in the entry point

Jahmaica
A: 

Try the following

$text = $item->introtext;
$newText = strip_tags($text);
Roland
hmm could work aswell
Deefjuh
A: 

typecast the object into a string before you feed it into the function.

$text = (string) $item->introtext;

Deefjuh