The Little Guy Posted October 4, 2009 Share Posted October 4, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/176468-remove-unknown-characters/ Share on other sites More sharing options...
ProXy_ Posted October 4, 2009 Share Posted October 4, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/176468-remove-unknown-characters/#findComment-930204 Share on other sites More sharing options...
The Little Guy Posted October 4, 2009 Author Share Posted October 4, 2009 I need all the characters though, I just don't want them to be formatted, where \0 = null I want \0 = \0 if that makes sense... Quote Link to comment https://forums.phpfreaks.com/topic/176468-remove-unknown-characters/#findComment-930205 Share on other sites More sharing options...
Alex Posted October 4, 2009 Share Posted October 4, 2009 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(). Quote Link to comment https://forums.phpfreaks.com/topic/176468-remove-unknown-characters/#findComment-930206 Share on other sites More sharing options...
ProXy_ Posted October 4, 2009 Share Posted October 4, 2009 sorry, i actually ment to use preg_replace in my code. its just so many years of the ereg_replace i'll be sure to note. Quote Link to comment https://forums.phpfreaks.com/topic/176468-remove-unknown-characters/#findComment-930214 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.