Forum Moderators: coopster

Message Too Old, No Replies

Replace wildcard

         

gosman

4:32 pm on Jan 21, 2008 (gmt 0)

10+ Year Member



I have an xml feed that is html encoded. It returns some strings that don't unencode.

Example &#x0D

Sometimes these are grouped together

Example

&#x0A&#x09&#x09

I know the following won't work, but is there a wildcard function that would do similar.

$output=str_replace('&#x0*','',$html);

PHP_Chimp

4:52 pm on Jan 21, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Have a look at preg_replace [uk2.php.net] as that can take regular expressions.

<edit>
&#x09 is a tab, so you may want to use -
str_replace('&#x09', '\t', $input);
although that wont affect your display at all.
&#0A is a line feed you may want -
str_replace('&#x0A', '<br />\n', $input);

Or you may want to just look for all hex characters with a value of less than 20 and remove those, as they are all control characters.
preg_replace('%&#x[0-1]?[0-9a-f]%i', '', $input);

[edited by: PHP_Chimp at 5:09 pm (utc) on Jan. 21, 2008]

gosman

5:02 pm on Jan 21, 2008 (gmt 0)

10+ Year Member



Hi PHP_Chimp

I have, but I can't get my head around it. Brain is not as fast as it was :-)

PHP_Chimp

5:10 pm on Jan 21, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I guess I was editing my post when you replied, so this is just so you see another post and come back ;)

gosman

5:20 pm on Jan 21, 2008 (gmt 0)

10+ Year Member



PHP_Chimp

I did read it before the edit. Your a gentleman.

preg_replace('%&#x[0-1]?[0-9a-f]%i', '', $input);

Works a treat.