Page 1 of 1

[SOLVED] BUG: highlight_string() don't like <?php on sa

Posted: Fri Mar 04, 2005 5:18 am
by Chris Corbyn
Possible bug in the highlight_ functions!.... :roll:

When puuting, for example this code into highlight_string() errors are returned.

Code: Select all

echo "<?php\r\n";
I get errors
echo "<?php
Warning: Unexpected character in input: ''' (ASCII=92) state=1 in /home/chriscor/public_html/phpdn/highlight/test.php on line 34
r
Warning: Unexpected character in input: ''' (ASCII=92) state=1 in /home/chriscor/public_html/phpdn/highlight/test.php on line 34
n
";
Yes the code is sent as a string (from a textarea and I do stripslashes on it before running highlight_string() - test it yourself)

This has to be a bug surely? highlight_string() can't winge about code that is not wrong can it?

I mean imagine that was proper code to fwrite a php file on-the-fly? Nothing wrong with it. I did actually run this on some code that I have with a similar situation whereby the code works but highlight_string() gives me errors.

NOTE: highlight_file(); gives the same error!!!!

Any clues (or workarounds?) :?

Posted: Fri Mar 04, 2005 5:21 am
by Chris Corbyn
I'm just gonna quickly test if addslashes() [that's gonna be alot of slashes if from textarea - 2 fold] allows the functions to work correctly but then I'll have to see if stripslashes() works on the output.

Even if nobody knows the answer but can confirm my suspicions it would be great...

EDIT: Nope that doesn't make the blindest bit of difference

Posted: Fri Mar 04, 2005 6:25 am
by Chris Corbyn
It's ok I think the workaround is to append/prepend <?php tags ?> to the whole chunk of code (I'll need to do a twisty preg_match to make sure they aren't there already). Then take them back out again after highlight_string has been run.

I wonder if I should report this a bug? Would anybody else bother?

Cheers :lol:

Posted: Fri Mar 04, 2005 8:01 am
by feyd
there's no bug. If the code doesn't have <?php..?> in the correct places, all bets are off.

Posted: Fri Mar 04, 2005 8:32 am
by Chris Corbyn
Oh ok... fair enough. I'll do my preg's to make sure it fits together.

Thanks very much :)