函数:AddSlashes()
--------------------------------------------------------------------------------
字符串处理函数库
AddSlashes
字符串加入斜线。语法: string addslashes(string str);返回值: 字符串函数种类: 资料处理
内容说明
本函数使需要让数据库处理的字符串,引号的部份加上斜线,以供数据库查询 (query) 能顺利运作。这些会被改的字符包括单引号 (')、双引号 (")、反斜线 backslash (\) 以及空字符 NUL (the null byte)。
--------------------------------------------------------------------------------
字符串处理函数库
AddSlashes
字符串加入斜线。语法: string addslashes(string str);返回值: 字符串函数种类: 资料处理
内容说明
本函数使需要让数据库处理的字符串,引号的部份加上斜线,以供数据库查询 (query) 能顺利运作。这些会被改的字符包括单引号 (')、双引号 (")、反斜线 backslash (\) 以及空字符 NUL (the null byte)。
^--不对吧?匹配空行?
<?
$u='*';
$temp = "<?//ssss";
if(ereg("<\?//$u", $temp))
echo "ok";
?>
http://www.phpe.net/articles/22.shtml
$patterns=array('(\*)','(\.)','(\[)','(\])');
$replace=array('\\\1','\\\1','\\\1','\\\1');
$u = preg_replace ($patterns, $replace, $u);
<script language=Javascript>
<!--
function ckform() {
with (document.addform){
if(name.value=="") {
alert("您必须输入您的名字!\nPlease input your names!");
name.focus();
return false;
}
if(email.value=="") {
alert("您必须输入您的E-mail地址!\nPlease input your mail!");
email.focus();
return false;
}
var pattern=/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/;
if(!pattern.test(email.value)){
alert("请输入正确的邮箱地址!\nE-mail not accept!");
email.focus();
return false;
}
var pattern=/([!\@\#\$%^&*()+|\\{}:;?<>`])+/;
if((pattern.test(name.value))) {
alert("您的姓名里不能包含非法字符!\nName not accept!");
name.focus();
return false;
}
var pattern=/^(http:\/\/)[A-Za-z0-9\-]+/;
if( (!pattern.test(url.value)) && (url.value!="http://") ) {
alert("请正确输入您的主页!\nHomepage not accept!");
url.focus();
return false;
}
var pattern=/([!\@\#\$%^&*+|\\{}?<>`])+/;
if( (pattern.test(subject.value)) || (subject.value=="") ) {
alert('留言主题不能为空且不能有非法字符!\n Subject not accept!');
subject.focus();
return false;
}
var pattern=/([!\@\#\$%^&*+|\\{}?<>`])+/;
if( (pattern.test(message.value)) || (message.value=="") ) {
alert('您的留言不能为空且不能有非法字符!\n Message not accept!');
message.focus();
return false;
}
}
return true;
}
//-->
</script>
http://www.php.net/manual/zh/function.preg-quote.php
echo preg_quote("[]?+.*$^(){}"); // out \[\]\?\+\.\*\$\^\(\)\{\}
(PHP 3>= 3.0.9, PHP 4 )preg_quote -- Quote regular expression characters
Description
string preg_quote ( string str [, string delimiter])
preg_quote() takes str and puts a backslash in front of every character that is part of the regular expression syntax. This is useful if you have a run-time string that you need to match in some text and the string may contain special regex characters. If the optional delimiter is specified, it will also be escaped. This is useful for escaping the delimiter that is required by the PCRE functions. The / is the most commonly used delimiter.The special regular expression characters are: . \\ + * ? [ ^ ] $ ( ) { } = ! < > | :
例子 1. $keywords = "$40 for a g3/400";
$keywords = preg_quote ($keywords, "/");
echo $keywords; // returns \$40 for a g3\/400
例子 2. Italicizing a word within some text// In this example, preg_quote($word) is used to keep the
// asterisks from having special meaning to the regular
// expression.$textbody = "This book is *very* difficult to find.";
$word = "*very*";
$textbody = preg_replace ("/".preg_quote($word)."/",
"<i>".$word."</i>",
$textbody);
User Contributed Notes
preg_quote
There are no user contributed notes for this page.
就是这样用。
\*\[\]