mirror of
https://github.com/php/web-php.git
synced 2026-04-29 01:43:15 +02:00
Add FAQ about adding slashes via regular expression.
This commit is contained in:
@@ -382,6 +382,20 @@ http://leonard.staff.imaginet.fr/Doc/php/configuration_NT.html</a>.
|
||||
while (list($var, $value) = each($HTTP_POST_VARS)) {
|
||||
echo "$var = $value<br>\n";
|
||||
}</PRE>
|
||||
<P>
|
||||
</DD>
|
||||
|
||||
<DT><B>
|
||||
I need to convert all single-quotes (') to a backslash followed by
|
||||
a single-quote. How can I do this with a regular expression?
|
||||
</B></DT>
|
||||
<DD>
|
||||
First off, take a look at the <A href="manual/function.addslashes.php3">addslashes()</A> function. It will do
|
||||
exactly what you want.
|
||||
<P>
|
||||
The ereg_replace magic you're looking for, however, is simply:<PRE>
|
||||
$escaped = ereg_replace("'", "\\'", $input);</PRE>
|
||||
<P>
|
||||
</DD>
|
||||
|
||||
<DT><B>
|
||||
|
||||
Reference in New Issue
Block a user