![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Expert Programmer
|
Even from time to time I get thrown astray on a weird bug in which I am usually looking right at the problem, yet still can not figure out what is wrong.
This is my code: <? $subject = "<td width=\"150\" background=\"images/bg_menu.gif\" bgcolor=\"#CCCCCC\"> ##if: SESSION_SHOWPREFS##<div class='ptrten' onClick='change_pref(\"STRSEL\")'><INPUT ##if: STRSEL##CHECKED##fi: STRSEL## TYPE=RADIO NAME=sgw VALUE='str'> STRSEL</div> <div class='ptrten' onClick='change_pref(\"GAYSEL\")'><INPUT ##if: GAYSEL##CHECKED##fi: GAYSEL## TYPE=RADIO NAME=sgw VALUE='gay'> GAYSEL</div> <div class='ptrten' onClick='change_pref(\"ANYSEL\")'><INPUT ##if: ANYSEL##CHECKED##fi: ANYSEL## TYPE=RADIO NAME=sgw VALUE='any'> ALLSEL</div>##fi: SESSION_SHOWPREFS## ##if: SESSION_HIDEPREFS##<span class='ptrten' onClick='unhide()'>>>> Set Preferences</span>##fi: SESSION_HIDEPREFS##' "; #//now try to match the string... $match_string = '/##if:[\s]*SESSION_SHOWPREFS##(.+)##fi:[\s]*SESSION_SHOWPREFS##/U'; $result = preg_match( $match_string, $subject, $captured ); if( $result === 0 ) print "\nResult returned as 0"; if( $result === false ) print "\nResult returned false"; #//just out of curiosity.. $it_is_false = false; $it_is_true = true; print "\nFALSE: $it_is_false, TRUE: $it_is_true\n"; #//now the data... print_r( $capture ); print "\n"; ?> this is my output: -bash-2.05b$ php -e preg_test.php Result returned as 0 FALSE: , TRUE: 1 -bash-2.05b$ Perhaps someone can tell me what I am overlooking here... I am expected it to return 1, and match the following section within the subject: ##if: SESSION_SHOWPREFS##<div class='ptrten' onClick='change_pref(\"STRSEL\")'><INPUT ##if: STRSEL##CHECKED##fi: STRSEL## TYPE=RADIO NAME=sgw VALUE='str'> STRSEL</div> <div class='ptrten' onClick='change_pref(\"GAYSEL\")'><INPUT ##if: GAYSEL##CHECKED##fi: GAYSEL## TYPE=RADIO NAME=sgw VALUE='gay'> GAYSEL</div> <div class='ptrten' onClick='change_pref(\"ANYSEL\")'><INPUT ##if: ANYSEL##CHECKED##fi: ANYSEL## TYPE=RADIO NAME=sgw VALUE='any'> ALLSEL</div>##fi: SESSION_SHOWPREFS## Any help would be appreciated, thanks in advance ![]()
__________________
Clifford Matthew Roche <geek@cliffordroche.com> Web Hosting: http://www.crd-hosting.com Consulting: http://www.crdev-consulting.com |
|
|
|
|
|
#2 |
|
Expert Programmer
|
Most interestingly enough if you use the following pattern to match it works fine...
$match_string = '/##if:[\s]*SESSION_SHOWPREFS##([^z]*)##fi:[\s]*SESSION_SHOWPREFS##/U'; It would seem that using (.+) is not matching something within the context of the subject... Any ideas?
__________________
Clifford Matthew Roche <geek@cliffordroche.com> Web Hosting: http://www.crd-hosting.com Consulting: http://www.crdev-consulting.com |
|
|
|
|
|
#3 |
|
Expert Programmer
|
Anyway, problem solved.. just used the following character class (I know it is redundant, but it fixed the problem)
[.\w\W\s\S]
__________________
Clifford Matthew Roche <geek@cliffordroche.com> Web Hosting: http://www.crd-hosting.com Consulting: http://www.crdev-consulting.com |
|
|
|
|
|
#4 |
|
Programming Guru
![]() ![]() ![]() |
Glad ya got it worked out....
A question: Why do these lines of code? Were you testing to see how the booleans would appear? $it_is_false = false; $it_is_true = true; print "\nFALSE: $it_is_false, TRUE: $it_is_true\n";
__________________
http://jasonpowers.net "There are a thousand hacking at the branches of evil to one who is striking at the root." |
|
|
|
|
|
#5 |
|
Expert Programmer
|
Yeah, I know that PHP generally tends to hold the following statements true:
'0' = 0 = "0" = flase and '1' = n = "n" = true (for n = (0,oo]) And what I did to insure that there were no errors in my original source code is I stucka print statement infront of preg_match which resulted in a 0, I just wanted to make sure that PHP was not formatting my FALSE to a 0 before printing it out, so I threw that in there to check when I wrote that test script. I still find the problem to illude me, according to the Perl Regexp guide, the character '.' should match *ANY* character, but for some reason it was refusing to match one of the viewable characters in the string I included in that script (posted above). The solution [.\w\W\s\S]* is not a nice one, but it does work.. however redundant it may actually be. I do not see this is posing as a performance hit however since '.' would have been evaluated much the same as the character class I provided. Perhaps this is a bug in PHP4? Or perhaps I am just misinformed on the use of the '.' character class. In any case, the script I was debugging for the last two days is now much closer to being debugged, lol.
__________________
Clifford Matthew Roche <geek@cliffordroche.com> Web Hosting: http://www.crd-hosting.com Consulting: http://www.crdev-consulting.com |
|
|
|
|
|
#6 |
|
Programming Guru
![]() ![]() ![]() |
It seems to me that your initial RE should work... but I have not played with Perl REs in a while. As far as the performance degradation, I don't think there will be a noticeable difference, if any at all.
__________________
http://jasonpowers.net "There are a thousand hacking at the branches of evil to one who is striking at the root." |
|
|
|
|
|
#7 |
|
Expert Programmer
|
I suppose the ultimate way to find out is to run the same regexp through a Perl system and see how that fairs... now the only thing is, that I do not like Perl enough to waste the time to do that... but then again if I get bored this weekend I will find out.
If it runs through perl I will send a bug report (after I check to see that one does not exist first) to the lovely people behind the scenes of PHP. I suspect bug moreso then anything else though... the purpose of that character class is to match EVERYTHING from every source I have read to date.
__________________
Clifford Matthew Roche <geek@cliffordroche.com> Web Hosting: http://www.crd-hosting.com Consulting: http://www.crdev-consulting.com |
|
|
|
|
|
#8 |
|
Programming Guru
![]() ![]() ![]() |
Yup, that's what most documentation seems to read. Let me know how it turns out.
__________________
http://jasonpowers.net "There are a thousand hacking at the branches of evil to one who is striking at the root." |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|