Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jul 20th, 2004, 4:43 PM   #1
kurifu
Expert Programmer
 
kurifu's Avatar
 
Join Date: Jul 2004
Location: Halifax, Nova Scotia (Canada)
Posts: 784
Rep Power: 5 kurifu is on a distinguished road
Send a message via ICQ to kurifu Send a message via MSN to kurifu
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 &lt;geek@cliffordroche.com&gt;
Web Hosting: http://www.crd-hosting.com
Consulting: http://www.crdev-consulting.com
kurifu is offline   Reply With Quote
Old Jul 20th, 2004, 5:10 PM   #2
kurifu
Expert Programmer
 
kurifu's Avatar
 
Join Date: Jul 2004
Location: Halifax, Nova Scotia (Canada)
Posts: 784
Rep Power: 5 kurifu is on a distinguished road
Send a message via ICQ to kurifu Send a message via MSN to kurifu
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 &lt;geek@cliffordroche.com&gt;
Web Hosting: http://www.crd-hosting.com
Consulting: http://www.crdev-consulting.com
kurifu is offline   Reply With Quote
Old Jul 20th, 2004, 5:59 PM   #3
kurifu
Expert Programmer
 
kurifu's Avatar
 
Join Date: Jul 2004
Location: Halifax, Nova Scotia (Canada)
Posts: 784
Rep Power: 5 kurifu is on a distinguished road
Send a message via ICQ to kurifu Send a message via MSN to kurifu
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 &lt;geek@cliffordroche.com&gt;
Web Hosting: http://www.crd-hosting.com
Consulting: http://www.crdev-consulting.com
kurifu is offline   Reply With Quote
Old Jul 20th, 2004, 6:24 PM   #4
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,466
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
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."
Infinite Recursion is offline   Reply With Quote
Old Jul 20th, 2004, 11:32 PM   #5
kurifu
Expert Programmer
 
kurifu's Avatar
 
Join Date: Jul 2004
Location: Halifax, Nova Scotia (Canada)
Posts: 784
Rep Power: 5 kurifu is on a distinguished road
Send a message via ICQ to kurifu Send a message via MSN to kurifu
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 &lt;geek@cliffordroche.com&gt;
Web Hosting: http://www.crd-hosting.com
Consulting: http://www.crdev-consulting.com
kurifu is offline   Reply With Quote
Old Jul 21st, 2004, 7:55 AM   #6
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,466
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
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."
Infinite Recursion is offline   Reply With Quote
Old Jul 22nd, 2004, 12:30 AM   #7
kurifu
Expert Programmer
 
kurifu's Avatar
 
Join Date: Jul 2004
Location: Halifax, Nova Scotia (Canada)
Posts: 784
Rep Power: 5 kurifu is on a distinguished road
Send a message via ICQ to kurifu Send a message via MSN to kurifu
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 &lt;geek@cliffordroche.com&gt;
Web Hosting: http://www.crd-hosting.com
Consulting: http://www.crdev-consulting.com
kurifu is offline   Reply With Quote
Old Jul 22nd, 2004, 12:33 AM   #8
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,466
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
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."
Infinite Recursion is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 1:38 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC