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
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

Link to comment
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

 

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.