Jump to content

Remove unknown characters


The Little Guy

Recommended Posts

I am building a xml file via php, and I am having a problem once in a while.

 

sometimes I get weird characters in the results, for example:

<title>Gimme What Ya Got (feat. Lil Wayne)�</title>

 

That little square before </title> is making the xml file fail.

 

the xml file error:

error on line 38 at column 45: Char 0x0 out of allowed range

 

So my question...

 

I can I remove all invalid characters before I insert them into my database?

Link to comment
https://forums.phpfreaks.com/topic/176468-remove-unknown-characters/
Share on other sites

well, lets see if this helps you out..

using eregi we can remove anything thats not a number or letter

 

here is an example of the code below: http://ju.nu/test/eregi.php

 

<?php

$string = "<title>Gimme What Ya Got (feat. Lil Wayne)?</title>";
$cleansedstring = ereg_replace("[^A-Za-z0-9]", "", $string );
echo $cleansedstring;

?>

 

hope this helps

well, lets see if this helps you out..

using eregi we can remove anything thats not a number or letter

 

here is an example of the code below: http://ju.nu/test/eregi.php

 

<?php

$string = "<title>Gimme What Ya Got (feat. Lil Wayne)?</title>";
$cleansedstring = ereg_replace("[^A-Za-z0-9]", "", $string );
echo $cleansedstring;

?>

 

hope this helps

 

You shouldn't use ereg_replace as it's depreciated and removed as of PHP 6.0.0, instead use preg_replace().

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.