Forum Moderators: coopster
I am trying to import some data from a text file into a table but am getting the following warning.
Warning: Unexpected character in input: '' (ASCII=2) state=1 in c:\phpdev\private\www\table.php on line 3
Is there a function i can pass the file through to do something with unexpected ASCII characters?
Is there a function i can pass the file through to do something with unexpected ASCII characters?
Well, what do you want to do with them? Get rid of them? This line will get rid of your "start of text" character:
preg_replace("/\002/", '', $string); You can also be a bit more drastic, by getting rid of everything that doesn't fit your definition of a good character. This one removes "special meaning" ASCII characters but leaves all the "typewriter" characters:
$string = preg_replace('/[^\040-\176]/', '', $string); Question: Are you just getting a warning, and the script then proceeds (basically) normally, or is the character really breaking your script.
The weird characters in the file are required as they are used to combine with a string to MD5 a password (vbulletin), i was just looking for a way to be able to work with the data without it halting my script as the special char was causing a warning followed by a parse error. I was trying to take the values from the text file, set them as values to new variables, and insert into a table.