Last active
September 22, 2023 02:52
-
-
Save aklump/3c4eb19896129267c4ab74650d7ed9f4 to your computer and use it in GitHub Desktop.
Add backslash to double quotes in a string where not already present.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Add backslash to double quotes unless already present. | |
*/ | |
class EscapeDoubleQuotes { | |
public function __invoke(string $query): string { | |
// This is four-backslashes because of preg--confusing--that's why this | |
// class exists to remove the confusion. | |
return preg_replace('/(?<!\\\\)"/', '\"', $query); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment