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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

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

Post 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?) :?
Last edited by Chris Corbyn on Fri Mar 04, 2005 8:32 am, edited 1 time in total.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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:
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

there's no bug. If the code doesn't have <?php..?> in the correct places, all bets are off.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Oh ok... fair enough. I'll do my preg's to make sure it fits together.

Thanks very much :)
Post Reply