note 42836 added to function.addcslashes
| From: | ruben at intesys dot it | Date: | Mon, 31 May 2004 13:51:55 +0000 |
| Subject: | note 42836 added to function.addcslashes | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-70347@lists.php.net to get a copy of this message | ||
jsAddSlashes for XHTML documents:
<?php
header("Content-type: text/xml");
print <<<EOF
<?xml version="1.0"?>
<html>
<head>
<script type="text/javascript">
EOF;
function jsAddSlashes($str) {
$pattern = array(
"/\\\\/" , "/\n/" , "/\r/" , "/\"/" ,
"/\'/" , "/&/" , "/</" ,
"/>/"
);
$replace = array(
"\\\\\\\\", "\\n" , "\\r" , "\\\"" ,
"\\'" , "\\x26" , "\\x3C" , "\\x3E"
);
return preg_replace($pattern, $replace, $str);
}
$message = jsAddSlashes("\"<Hello>\",\r\n'&World'\\!");
print <<<EOF
alert("$message");
</script>
</head>
<body>
<h1>Hello, World!</h1>
</body>
</html>
EOF;
?>
----
Manual Page -- http://www.php.net/manual/en/function.addcslashes.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+42836
Delete -- http://master.php.net/manage/user-notes.php?action=delete+42836&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+42836&report=yes
Search -- http://master.php.net/manage/user-notes.php