August 9th, 2004, 02:46 PM
Warning: Unexpected character in input: '' (ASCII=92) state=1
I'm using the highlight_string function in one of my scripts to output highlight some PHP code, but in a couple of places, I get the error message "Warning: Unexpected character in input: '' (ASCII=92) state=1 in...".
For example, what I would expect to see output as this:
...is actually been output as this:
$test = "This is a test";
I don't really understand what could be causing this, and would welcome any advice you could offer.
Warning: Unexpected character in input: '' (ASCII=92) state=1 in <etc etc etc>
"This is a test";
August 9th, 2004, 04:13 PM
Well, ascii 92 is a "\" character, which has special meaning in php. Remember that to actually display a "\" character, you need to type "\\".
August 9th, 2004, 04:39 PM
Hmm, that's confusing me a little.
The code I want to highlight is stored in a variable named $output. The reason I'm confused is because I have the line stripslashes($output); before highlight_string($output);, so surely the offending \ (before the first " mark from the looks of the error) should have been removed should it not? Or am I misunderstanding the way in which the stripslashes function works?
Can you possibly give me some advice as to what to do next?
Thanks for the help so far.
August 9th, 2004, 04:43 PM
You will likely need to remove the stripslashes, or even use addslashes instead. I'd have to see the code to make sure, but try that.
August 9th, 2004, 08:47 PM
When I removed the stripslashes line, the error above disappeared, but a different one appeared. However, the new error was caused by a bug elsewhere in the script it seems, which has now been fixed.
Thanks for all of your help. I couldn't have done this without it.