Jump to content

WARNING *whimper* why


GoneNowBye

Recommended Posts

preg_match_all("/(?:[^\\]|^)(?:\[link:([a-zA-Z0-9=,]*)\])/",stripslashes($_GET['d']),$matches);

 

is my line

 

Warning:  preg_match_all() [function.preg-match-all]: Compilation failed: unmatched parentheses at offset 41 in

 

what is going on! i dont get it, please help

 

dont comment on the security of $_GET d this is a local test page,

 

Havok

 

I dont get the error 'tis all

Link to comment
Share on other sites

My initial guess is this portion:

 

preg_match_all("/(?:[^\\]|^)(?:\[link:([a-zA-Z0-9=,]*)\])/",stripslashes($_GET['d']),$matches);

 

I believe you need 3 or 4 backslashes (I saw this before) to get a literal backslash. Let me find that post. Edit: Here it is

 

http://www.phpfreaks.com/forums/index.php/topic,301552.msg1427102.html#msg1427102

 

It's not a bug, you firstly need to account for what PHP thinks is an backslash escape sequence, you then need to account for what PCRE considers an escape sequence. You are using a double quote inside a double quoted string, thus meaning it needs to be escaped, there's one backslash. You then wish to match a backslash in your input string. In order to do this let's say we place a single quote in the string. PHP will see this as escaping the backslash which is supposed to be escaping the double quote, thus you need to escape it to prevent that happening. At this point we have 3 backslashes in our patterns. Out of these 3 only one will survive the PHP interpolation. Meaning the Regex pattern contains a single slash. The PCRE engine will assume this backslash is an escape sequence. In order to counter that we need to make sure 2 make it through the the PCRE engine, the only way to do this is add another 2 into the string. That's 5 backslashes.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.