Re: [PHP] String parsing issue in PHP 4.3.10?
On Wednesday 22 December 2004 08:18, John Holmes wrote: It is, I guess. ?php $a = ' ? '; $b = ' ? '; ? will work just fine. If you try to comment out either line, though, the PHP processing will end at the ? and spit out the rest as plain text. So, text can have as many ? as you want and the only issue comes when you try to comment one of them out. I'm sure it must be documented behaviour, because my syntax highlighting editor seems to be aware of it. When I stick // in front of $a, the colour for comments stop just before the ?. And a quick check of the manual confirms that it is documented behaviour. -- Jason Wong - Gremlins Associates - www.gremlins.biz Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * -- Search the list archives before you post http://marc.theaimsgroup.com/?l=php-general -- /* The 357.73 Theory: Auditors always reject expense accounts with a bottom line divisible by 5. unts */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] String parsing issue in PHP 4.3.10?
* Thus wrote Jason Wong: On Wednesday 22 December 2004 08:18, John Holmes wrote: It is, I guess. ?php $a = ' ? '; $b = ' ? '; ? will work just fine. If you try to comment out either line, though, the PHP processing will end at the ? and spit out the rest as plain text. So, text can have as many ? as you want and the only issue comes when you try to comment one of them out. I'm sure it must be documented behaviour, because my syntax highlighting editor seems to be aware of it. When I stick // in front of $a, the colour for comments stop just before the ?. And a quick check of the manual confirms that it is documented behaviour. http://php.net/language.basic-syntax.comments snip The one-line comment styles actually only comment to the end of the line or the current block of PHP code, whichever comes first. /snip Curt -- Quoth the Raven, Nevermore. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] String parsing issue in PHP 4.3.10?
Jason Wong wrote: On Wednesday 22 December 2004 03:53, Richard Lynch wrote: ? can be caught by PHP as the end of PHP mode, no matter where you put it in a string or not. You can't be serious? Or have I misunderstood you? ?php echo '?php ?'; ? Works as expected, ie displays ?php ?. I plead sleep deprivation, your honor. :-^ It's only in comments that ? gets funky. Though my solution *DOES* work to solve the given problem, no? -- Like Music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] String parsing issue in PHP 4.3.10?
I'm working on a script that will parse through a long string using regexs to pattern match a certain format. I'm having an issue with a '?' in a string being picked up as an end-of-code character, but only if the line before it is commented out. If the line before is NOT commented out, PHP processes the file as normal (errors out, but I can fix that). I'd appreciate it if someone else could run this script and see what happens. PHP Version: $ php --version PHP 4.3.10 (cli) (built: Dec 20 2004 10:45:58) Copyright (c) 1997-2004 The PHP Group Zend Engine v1.3.0, Copyright (c) 1998-2004 Zend Technologies PHP Config line: ./configure --with-mysql --with-apxs2=/pub/apache/bin/apxs --with-mcrypt=/usr/local/lib --with-curl=/usr/local --enable-ftp --with-imap=/usr/local/imap --with-jpeg --with-jpeg-dir=/usr/local/lib --with-png --with-png-dir=/usr/local/lib --with-zlib-dir=/usr/local/lib --with-gd --with-freetype --with-freetype-dir=/usr/local/lib --with-ttf Unexpected results: If line 16 (indicated below) is commented out, the '?' in the string on line 17 makes PHP stop parsing and the rest of the script is simply dumped to stdout. If line 16 is NOT commented out, the '?' is NOT picked up as being a PHP tag and it parses the script as PHP. Environment: Running in CLI on Redhat 9, current versions of all applicable software. The exact same behavior occurs when running as a webpage with Apache 2.0.52. == ? $notes = '14 Mar 2004 18:46 Jay Brown added item to shop14 Mar 2004 19:15 Jay Brown changed production status to Ready for Publishing14 Mar 2004 19:32 Published by Jay Brown15 Mar 2004 09:22 Published by bill Smith15 Mar 2004 09:57 Published by Bill Smith16 Jun 2004 14:28 Julie Johnson repriced all options. 16 Jun 2004 14:29 Julie Johnson repriced all options.6/16/2004 14:29 Julie Johnson committed pricing changes. 29 Jun 2004 09:21 Published by Bill Smith07 Jul 2004 11:42 Bill Smith changed production status to Ready for Publishing 07 Jul 2004 13:44 Published by Bill Smith20 Jul 2004 13:07 Bonie Jackson changed production status to Ready for Publishing 21 Jul 2004 08:36 Published by Bill Smith'; # Attempt to split the notes # echo $notes.\n; $time_exp = '/\d{1,2} \w{3} \d{4} \d{2}:\d{2}/'; $note_exp = '/\d{1,2} \w{3} \d{4} \d{2}:\d{2}\s? [!-~ ]+/'; // COMMENT OUT THIS LINE $note_exp = '/\d{1,2}\/\d{1,2}\/\d{2,4} \d{2}:\d{2}\s? [!-~]+/'; // PHP STOPS PARSING HERE // Attempt to split the notes... if (preg_match($note_exp, $notes) == 0) { echo No match found for .$record['ID'].!:\n; echo $notes.\n\n\n; continue; } $count = preg_match_all ($note_exp, $notes, $splits); $notes = $splits[0]; // Check for notes within notes... This can happen when there are a missing line break in a note... $temp = array(); foreach ($notes as $note) { while (preg_match($note_exp, $note) 0) { preg_match_all($note_exp, $note, $splits, PREG_OFFSET_CAPTURE, 5); // Find the next substring match... if (isset ($splits[0][0])) { $temp[] = substr($note, 0, $splits[0][0][1]); $note = $splits[0][0][0]; } else break; } $temp[] = $note; } $notes = $temp; // Remove any duplicate notes $unique_notes = array(); foreach ($notes as $note) { if (!in_array($note, $unique_notes)) $unique_notes[] = $note; } # Split the note into different fields for storing in the DB... $item_notes = array(); $count = 1; foreach ($unique_notes as $note) { // Find the timestamp... preg_match_all ($time_exp, $note, $splits); $timestamp = $splits[0][0]; // Convert it to a legitimate timestamp... $ansi_timestamp = date('Y-m-d H:i:s', strtotime($timestamp)); // Find the note itself... $note_divider = strpos($note, ''); $note_only = trim(substr($note, $note_divider+1)); $a = array(); $a['RecordID'] = $record['Target']; $a['Timestamp'] = $ansi_timestamp; $a['Log'] = addslashes($note_only); $all_notes[] = $a; $count++; } foreach ($all_notes as $data) { echo '{ Timestamp='.$data['Timestamp'].', RecordID = '.$data['RecordID'].', Log='.$data['Log'].' }'; } ? == -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] String parsing issue in PHP 4.3.10?
From: Steve Brown [EMAIL PROTECTED] Unexpected results: If line 16 (indicated below) is commented out, the '?' in the string on line 17 makes PHP stop parsing and the rest of the script is simply dumped to stdout. If line 16 is NOT commented out, the '?' is NOT picked up as being a PHP tag and it parses the script as PHP. Quote: The one-line comment styles actually only comment to the end of the line or the current block of PHP code, whichever comes first. This means that HTML code after // ? WILL be printed: ? skips out of the PHP mode and returns to HTML mode, and // cannot influence that. If asp_tags configuration directive is enabled, it behaves the same with // %. From: http://www.php.net/manual/en/language.basic-syntax.comments.php I remember running into this, also, so don't feel bad about not noticing it. ;) ---John Holmes... UCCASS - PHP Survey System http://www.bigredspark.com/survey.html -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] String parsing issue in PHP 4.3.10?
On Wednesday 22 December 2004 01:12, Steve Brown wrote: I'm working on a script that will parse through a long string using regexs to pattern match a certain format. I'm having an issue with a '?' in a string being picked up as an end-of-code character, but only if the line before it is commented out. If the line before is NOT commented out, PHP processes the file as normal (errors out, but I can fix that). That suggests to me you have some mismatched quotes somewhere. Get yourself an editor that does syntax highlighting then you can easily see where your quoted strings begin and end. -- Jason Wong - Gremlins Associates - www.gremlins.biz Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * -- Search the list archives before you post http://marc.theaimsgroup.com/?l=php-general -- /* Minnie Mouse is a slow maze learner. */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] String parsing issue in PHP 4.3.10?
Quote: The one-line comment styles actually only comment to the end of the line or the current block of PHP code, whichever comes first. This means that HTML code after // ? WILL be printed: ? skips out of the PHP mode and returns to HTML mode, and // cannot influence that. If asp_tags configuration directive is enabled, it behaves the same with // %. I read that too, but my problem is with the fact that if the previous line is NOT commented out, the script works fine. You will notice that the previous line also contains a '?' sequence, so I'm confused as to why this would die on one line but not the other? Or is this some freak combination of comments and PHP tags? :-o At any rate, I managed to work around this issue by encapsulating the '\s?' partion of the expression in parentheses. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] String parsing issue in PHP 4.3.10?
Steve Brown wrote: I'm working on a script that will parse through a long string using regexs to pattern match a certain format. I'm having an issue with a '?' in a string being picked up as an end-of-code character, but only No need to run it. ? can be caught by PHP as the end of PHP mode, no matter where you put it in a string or not. You can get around this by using something like: //$note_exp = '/\d{1,2} \w{3} \d{4} \d{2}:\d{2}\s? [!-~ ]+/'; // COMMENT OUT THIS LINE $note_exp = '/\d{1,2} \w{3} \d{4} \d{2}:\d{2}\s?' . ' [!-~]+/'; Other possible solutions: Use ?\ and PHP inside of and maybe PHP will interpret that as what you want. I'm also not a fan of a single \ inside of '' myself, even if the manual has finally said it's kosher. Maybe cuz I'm just old, and remember when that was not specifically allowed in the manual. :-) So I'd use \\ everywhere you have \ currently. Actually, you may be triggering a PHP bug in the string parsing engine, by using \ instead of \\. You do realize that \ *IS* one of the two special characters inside of ''s, the other being ' itself, right?... -- Like Music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] String parsing issue in PHP 4.3.10?
On Wednesday 22 December 2004 03:53, Richard Lynch wrote: ? can be caught by PHP as the end of PHP mode, no matter where you put it in a string or not. You can't be serious? Or have I misunderstood you? ?php echo '?php ?'; ? Works as expected, ie displays ?php ?. -- Jason Wong - Gremlins Associates - www.gremlins.biz Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * -- Search the list archives before you post http://marc.theaimsgroup.com/?l=php-general -- /* The typewriting machine, when played with expression, is no more annoying than the piano when played by a sister or near relation. -- Oscar Wilde */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: Re: [PHP] String parsing issue in PHP 4.3.10?
You will notice that the previous line also contains a '?' sequence, so I'm confused as to why this would die on one line but not the other? Or is this some freak combination of comments and PHP tags? :-o It is, I guess. ?php $a = ' ? '; $b = ' ? '; ? will work just fine. If you try to comment out either line, though, the PHP processing will end at the ? and spit out the rest as plain text. So, text can have as many ? as you want and the only issue comes when you try to comment one of them out. ---John Holmes... UCCASS - PHP Survey System http://www.bigredspark.com/survey.html -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php