roydukkey Posted September 25, 2009 Share Posted September 25, 2009 What is the difference between the two? Tried for hours to fix this and don't know exactly the reasons it works. preg_replace("/\$inc\s+\(([^\)]+)\)/im", $replace, $subject); // Breaks - single quotes preg_replace('/\$inc\s+\(([^\)]+)\)/im', $replace, $subject); // Works - double quotes Quote Link to comment https://forums.phpfreaks.com/topic/175450-what-is-the-difference-between-double-and-single-quotes-in-regex/ Share on other sites More sharing options...
Zane Posted September 25, 2009 Share Posted September 25, 2009 because the top one parses the $inc as a variable...if I had to guess. Quote Link to comment https://forums.phpfreaks.com/topic/175450-what-is-the-difference-between-double-and-single-quotes-in-regex/#findComment-924574 Share on other sites More sharing options...
thebadbad Posted September 25, 2009 Share Posted September 25, 2009 To escape a dollar sign (followed by one or more characters allowed in variable names) inside double quotes in a preg_* call, you actually need three backslashes. The first one suppresses the variable meaning, the second escapes the first backslash, and then you need a third to suppress the regex meaning ($ being the end-of-string char in regex). Quote Link to comment https://forums.phpfreaks.com/topic/175450-what-is-the-difference-between-double-and-single-quotes-in-regex/#findComment-924697 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.