Forum Moderators: coopster

Message Too Old, No Replies

Unexpected character

         

joedub

11:46 am on Dec 22, 2004 (gmt 0)

10+ Year Member



Hello,

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?

timster

4:01 pm on Dec 22, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to WebMasterWorld, joedub!

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.

joedub

4:25 pm on Dec 22, 2004 (gmt 0)

10+ Year Member



Hello,

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.

timster

7:55 pm on Dec 22, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



the special char was causing a warning followed by a parse error

Ouch, that stings! But an ASCII char 2 in an input file shouldn't kill a PHP script. (Just tried it here without incident.)

Can you post a code snippet so I can see the problem?