View Full Version : remove an extra characters from php
amit_shetye
12-02-2005, 09:52 AM
hi,
i'm currently working on rss feeder. In that i'm parsing xml values to php.
but along with the xml values i'm getting some unwanted characters to like
some html tags(i.e. <i> </i>,<br> <br> etc...).
so in php it is showing as below
for eg. : legal+team.+%3Cbr%3E%3Cbr%
in the above example legal+team. are the xml values getting from the rss along with an extra chracter %3Cbr%3E%3Cbr%.
so how should i remove those unwanted extra characters in php.
anybody is having any idea??
thanx in advance..:)
regards
amit
Element
12-02-2005, 07:13 PM
Well you could use str_replace before outputting. str_replace([TO_REPLACE], [REPLACEMENT], [STRING])
ralph l mayo
12-02-2005, 10:40 PM
Are HTML tags the only thing you want to filter out?
$test = '<i>a string</i> with <br />some <a href="http://google.com">unwanted <br>tags</a>';
$test = preg_replace('/<br(>| \/>|\/>)/', "\n", $test); // replaces breaks with newlines, just delete this line if that's not something you want
$test = preg_replace('/<.*?>/', '', $test);
echo $test;
You might need to expand the regex if there is other formatting that needs to go.
firepages
12-03-2005, 01:16 AM
or use strip_tags() (http://www.php.net/strip_tags)
Element
12-03-2005, 01:32 AM
or use strip_tags() (http://www.php.net/strip_tags)
The reason I gave him the code I had becaue it looks like this HTML is not in runnable code. Or XML or something. strip_tags() would work for regular HTML only as far as I know.
firepages
12-03-2005, 02:30 AM
strip_tags() works for anything that parses like a tag <.*></.*> so it should remove custom xml tags etc , but newlines and tabs etc may have to be removed via trim or str_replace. (which I prefer over any form of regular expression if appropriate)
You are right in that it looks like the string has been urlencoded or similar so further operations may be needed to reverse that process first.
how about this:
echo strip_tags(urldecode('legal+team.+%3Cbr%3E%3Cbr%'));
ralph l mayo
12-03-2005, 03:17 AM
or use strip_tags() (http://www.php.net/strip_tags)
Argh I searched my copy of the PHP help for that on a vague recollection but I neglected the underline. I don't know why half this crap is in the base language and why they can't standardize the names a bit. strip_tags() is what you want, regardless.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.