Just a quick question for my own curiosity mostly. Hopefully someone can shed light on this.
I have this code
Code: Select all
<?php
$string = "breaks\kristin.txt";
preg_match("/breaks\\\([0-9A-Za-z\-_]+)\.txt/i", $string, $matches);
if(isset($matches[1])) {
echo $matches[1];
}
?>My big question is why I need the triple backslash? I thought I would only need two, one back slash to escape the other.
However, if I use this code:
Code: Select all
<?php
$string = "breaks\kristin.txt";
preg_match("/breaks\\([0-9A-Za-z\-_]+)\.txt/i", $string, $matches);
if(isset($matches[1])) {
echo $matches[1];
}
?>Warning: preg_match(): Compilation failed: unmatched parentheses at offset 23 in /Volumes/DATA1/webserver/sandbox/break.php on line 5
Could someone explain? I would think that only two would be needed, wouldn't 3 backslashes leave one escaped, and another one escaping the opening parenthesis?