不能像php那样的语言一样定义,只能采用
function showAlert(str,alertw,alerth){
var alertw=arguments[1]?arguments[1]:400;
var alerth=arguments[2]?arguments[2]:100;
}
这样的方式定义..
借肋于arguments 是实参数组
不能像php那样的语言一样定义,只能采用
function showAlert(str,alertw,alerth){
var alertw=arguments[1]?arguments[1]:400;
var alerth=arguments[2]?arguments[2]:100;
}
这样的方式定义..
借肋于arguments 是实参数组
用smarty插件,
function smarty_prefilter_chpath($tpl_source,&$smarty)
{
/*这个会将绝对路径也修正,不对
return preg_replace("/(<(img.*?src|link.*?href|script.*?src)=([\"']))(.*?)(\\3.*?>)/is","$1".SKINTPL."$4$5",$tpl_source);
*/
/*这个会将js也修正
return preg_replace("/(<(img.*?src|link.*?href|script.*?src)=([\"']))(([^(http:\/\/)])(.*?))(\\3.*?>)/is","$1".SKINTPL."$5$6$7",$tpl_source);
*/
/*这个不修正js */
return preg_replace("/(<(img.*?src|link.*?href)=([\"']))(([^(http:\/\/)])(.*?))(\\3.*?>)/is","$1".SKINTPL."$5$6$7",$tpl_source);
}文件取名prefilter.chpath.php,放到plugins,用 $smarty->load_filter('pre','chpath');就行了
最新修改此函数如下:
function smarty_prefilter_chpath($tpl_source,&$smarty)
{
/*
return preg_replace("/(<(img.*?src|link.*?href|script.*?src)=([\"']))(.*?)(\\3.*?>)/is","$1".SKINTPL."$4$5",$tpl_source);
*/
/*
return preg_replace("/(<(img.*?src|link.*?href|script.*?src)=([\"']))(([^(http:\/\/)])(.*?))(\\3.*?>)/is","$1".SKINTPL."$5$6$7",$tpl_source);
*/
/*
return preg_replace("/(<(img.*?src|link.{1,100}href)=([\"']))(([^(http:\/\/|\{\$imgurl\})])(.*?))(\\3.*?>)/is","$1".SKINTPL."$5$6$7",$tpl_source);
*/
return preg_replace("/(<(img.*?src|link.{1,100}href)=([\"']))(images|style)(.*?)(\\3.*?>)/is","$1".SKINTPL."$4$5$6",$tpl_source);
} 这个记在这,留个记号
http://www.oncity.cc/p/test/jquery/search.html
jquery搜索提示的
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>jQuery 自动完成功能(优化版)</title>
<script type="text/javascript" src="jquery-1.3.1.js"></script>
</head>
<body>
<script type="text/javascript">
var highlightindex = -1;//表示当前高亮节点
var timeoutId;
$(document).ready(function() {
var wordInput = $("#word");//文本框
var wordInputOffset = wordInput.offset();//获得文本框位置
$("#auto").hide().css("border", "1px black solid").css("position", "absolute")
.css("top", wordInputOffset.top + wordInput.height() + 5 + "px")
.css("left", wordInputOffset.left + "px").width(wordInput.width() + 3 + "px");
wordInput.blur(function() {
autoHide();
});
wordInput.keyup(function(event) {
//处理文本框中的键盘事件
//如果输入字母,将文本框中最新信息发送给服务器
var myEvent = event || window.event;
var keyCode = myEvent.keyCode;//获得键值
if (keyCode == 27) {
var wordText = $("#word").val();
autoHide();
wordInput.text(wordText);
}
else {
if (keyCode >= 65 && keyCode <= 90 || keyCode == 8 || keyCode == 46 || keyCode == 32) { //8对应退格键,46对应删除键
var wordText = $("#word").val();//获得文本框中的内容
var autoNode = $("#auto");
if (wordText != "") {
clearTimeout(timeoutId);//对上次未完成的延时操作进行取消
//延时操作,减少与服务器的交互次数,延时500ms,防止用户操作过快
timeoutId = setTimeout(function() {
$.post("http://www.oncity.cc/p/test/jquery/search_result.php", {word:wordText}, function(data) {
if($("#word").val() =="" ) {
autoHide();
return;
}
var jqueryObj = $(data);//将dom对象data转换成jQuery的对象
var wordNodes = jqueryObj.find("word");//找到所有word节点
autoNode.html("");
wordNodes.each(function(i) { //i是索引,用来给id赋值
var wordNode = $(this);//获取单词内容
var newDivNode = $("<div>").attr("id", i).css("backgroundColor", "white");
newDivNode.html(wordNode.text()).appendTo(autoNode);//新建div节点,加入单词内容
//增加鼠标进入事件,高亮节点
newDivNode.mouseover(function() {
//将原来高亮的节点取消高亮
if (highlightindex != -1) {
$("#auto").children("div").eq(highlightindex)
.css("backgroundColor", "white");
}
//记录新的高亮索引
highlightindex = $(this).attr("id");
$(this).css("backgroundColor", "#3366CC").css("cursor","pointer");
});
//增加鼠标移出事件,取消节点高亮
newDivNode.mouseout(function() {
if (keyCode == 13) { //判断是否按下回车键
//下拉框有高亮
if (highlightindex != -1) {
lightEventHide();
highlightindex = -1;
} else {
alert("文本框中的[" + $("#word").val() + "]被提交了");
autoHide();
$("#word").get(0).blur();//让文本框失去焦点
}
//取消鼠标移出节点的高亮
//$(this).css("backgroundColor", "white");
}
}
);
//增加鼠标点击事件,可以进行补全
newDivNode.click(function() {
//取出高亮节点的文本内容
var comText = $(this).text();
autoHide();
highlightindex = -1;
//文本框内容变为高亮节点内容
$("#word").val(comText);
});
});
//添加单词内容到弹出框
if (wordNodes.length > 0) {
autoNode.show();
} else {
autoNode.hide();
highlightindex = -1;//弹出框隐藏,高亮节点索引设成-1
}
}, "xml");
}, 300);
}
else
{
autoNode.hide();
highlightindex = -1;
}
} else if (keyCode == 38 || keyCode == 40) { //判断是否输入的是向上38向下40按键
if (keyCode == 38) {
var autoNodes = $("#auto").children("div").css("background-color", "white");
if (highlightindex != -1) {
autoNodes.eq(highlightindex).css("background-color", "white");
highlightindex--;
} else {
lightEvent();
highlightindex = autoNodes.length - 1;
}
if (highlightindex == -1) {
highlightindex = autoNodes.length - 1;//如果改变索引值后index变成-1,则将索引值指向最后一个元素
}
lightEvent();
autoNodes.eq(highlightindex).css("backgroundColor", "#3366CC");
}
if (keyCode == 40) {
var autoNodes = $("#auto").children("div");
if (highlightindex != -1) {
autoNodes.eq(highlightindex).css("background-color", "white");
}
highlightindex++;
if (highlightindex == autoNodes.length) {
highlightindex = 0;//如果改变索引值等于最大长度,则将索引值指向第一个元素
}
lightEvent();
autoNodes.eq(highlightindex).css("backgroundColor", "#3366CC");
}
} else if (keyCode == 13) { //判断是否按下回车键
//下拉框有高亮
if (highlightindex != -1) {
lightEventHide();
highlightindex = -1;
} else {
alert("文本框中的[" + $("#word").val() + "]被提交了");
$("#auto").hide();
$("#word").get(0).blur();//让文本框失去焦点
}
//下拉框没有高亮
}
}
}
)
;
$("input[type='button']").click(function() {
alert("文本框中的[" + $("#word").val() + "]被提交了");
});
});
function lightEventHide(){
var comText = $("#auto").hide().children("div").eq(highlightindex).text();
$("#word").val(comText);
}
function lightEvent(){
var comText = $("#auto").children("div").eq(highlightindex).text();
$("#word").val(comText);
}
function autoHide(){
$("#auto").hide();
}
</script>
<h3>
<center>智能搜,打个 win 或 曼 字看看</center>
</h3>
<br />
<table align="center">
<tr><td>
<input type="text" id="word" maxlength=2048 size=55 />
<br/>
<td></tr>
<tr><td align="center">
<input type="button" value="OnCity 智能搜索"/>
</td></tr>
</table>
<br />
<div id="auto"></div>
</body>
</html>
首先,向写这篇文章的GG 或MM表示感谢!
如果你不断地建立不同的函数来检查或者操作字符串的一部分,现在你可能要放弃所有的这些函数,取而代之的用正则表达式。如果你对下列的问题都答“是的”,那么你肯定要考虑使用正则表达式了:
补充开始----------------------------
配中文字符的正则表达式: [\u4e00-\u9fa5]
匹配双字节字符(包括汉字在内):[^\x00-\xff]
匹配空行的正则表达式:\n[\s| ]*\r
匹配HTML标记的正则表达式:/<(.*)>.*<\/\1>|<(.*) \/>/
匹配首尾空格的正则表达式:(^\s*)|(\s*$)
匹配Email地址的正则表达式:\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*
匹配网址URL的正则表达式:^[a-zA-z]+://(\\w+(-\\w+)*)(\\.(\\w+(-\\w+)*))*(\\?\\S*)?$
匹配帐号是否合法(字母开头,允许5-16字节,允许字母数字下划线):^[a-zA-Z][a-zA-Z0-9_]{ 4,15 }$
匹配国内电话号码:(\d{ 3 }-|\d{ 4 }-)?(\d{ 8 }|\d{ 7 })?
匹配腾讯QQ号:^[1-9]*[1-9][0-9]*$
下表是元字符及其在正则表达式上下文中的行为的一个完整列表:
\ 将下一个字符标记为一个特殊字符、或一个原义字符、或一个后向引用、或一个八进制转义符。
^ 匹配输入字符串的开始位置。如果设置了 RegExp 对象的Multiline 属性,^ 也匹配 ’\n’ 或 ’\r’ 之后的位置。
$ 匹配输入字符串的结束位置。如果设置了 RegExp 对象的Multiline 属性,$ 也匹配 ’\n’ 或 ’\r’ 之前的位置。
* 匹配前面的子表达式零次或多次。
+ 匹配前面的子表达式一次或多次。+ 等价于 { 1, }。
? 匹配前面的子表达式零次或一次。? 等价于 { 0,1 }。
{ n } n 是一个非负整数,匹配确定的n 次。
{ n, } n 是一个非负整数,至少匹配n 次。
{ n,m } m 和 n 均为非负整数,其中n <= m。最少匹配 n 次且最多匹配 m 次。在逗号和两个数之间不能有空格。
? 当该字符紧跟在任何一个其他限制符 (*, +, ?, { n }, { n, }, { n,m }) 后面时,匹配模式是非贪婪的。非贪婪模式尽可能少的匹配所搜索的字符串,而默认的贪婪模式则尽可能多的匹配所搜索的字符串。
. 匹配除 "\n" 之外的任何单个字符。要匹配包括 ’\n’ 在内的任何字符,请使用象 ’[.\n]’ 的模式。
(pattern) 匹配pattern 并获取这一匹配。
(?:pattern) 匹配pattern 但不获取匹配结果,也就是说这是一个非获取匹配,不进行存储供以后使用。
(?=pattern) 正向预查,在任何匹配 pattern 的字符串开始处匹配查找字符串。这是一个非获取匹配,也就是说,该匹配不需要获取供以后使用。
(?!pattern) 负向预查,与(?=pattern)作用相反
x|y 匹配 x 或 y。
[xyz] 字符集合。
[^xyz] 负值字符集合。
[a-z] 字符范围,匹配指定范围内的任意字符。
[^a-z] 负值字符范围,匹配任何不在指定范围内的任意字符。
\b 匹配一个单词边界,也就是指单词和空格间的位置。
\B 匹配非单词边界。
\cx 匹配由x指明的控制字符。
\d 匹配一个数字字符。等价于 [0-9]。
\D 匹配一个非数字字符。等价于 [^0-9]。
\f 匹配一个换页符。等价于 \x0c 和 \cL。
\n 匹配一个换行符。等价于 \x0a 和 \cJ。
\r 匹配一个回车符。等价于 \x0d 和 \cM。
\s 匹配任何空白字符,包括空格、制表符、换页符等等。等价于[ \f\n\r\t\v]。
\S 匹配任何非空白字符。等价于 [^ \f\n\r\t\v]。
\t 匹配一个制表符。等价于 \x09 和 \cI。
\v 匹配一个垂直制表符。等价于 \x0b 和 \cK。
\w 匹配包括下划线的任何单词字符。等价于’[A-Za-z0-9_]’。
\W 匹配任何非单词字符。等价于 ’[^A-Za-z0-9_]’。
\xn 匹配 n,其中 n 为十六进制转义值。十六进制转义值必须为确定的两个数字长。
\num 匹配 num,其中num是一个正整数。对所获取的匹配的引用。
\n 标识一个八进制转义值或一个后向引用。如果 \n 之前至少 n 个获取的子表达式,则 n 为后向引用。否则,如果 n 为八进制数字 (0-7),则 n 为一个八进制转义值。
\nm 标识一个八进制转义值或一个后向引用。如果 \nm 之前至少有is preceded by at least nm 个获取得子表达式,则 nm 为后向引用。如果 \nm 之前至少有 n 个获取,则 n 为一个后跟文字 m 的后向引用。如果前面的条件都不满足,若 n 和 m 均为八进制数字 (0-7),则 \nm 将匹配八进制转义值 nm。
\nml 如果 n 为八进制数字 (0-3),且 m 和 l 均为八进制数字 (0-7),则匹配八进制转义值 nml。
\un 匹配 n,其中 n 是一个用四个十六进制数字表示的Unicode字符。
------------------------------补充结束
你是否正在写一些定制的函数来检查表单数据(比如在电子信箱地址中的一个@,一个点)
你是否写一些定制的函数,在一个字符串中循环每个字符,如果这个字符匹配了一个特定特征(比如它是大写的,或者它是一个空格),那么就替换它?
除了是令人不舒服的字符串检查和操作方法,如果没有有效率地写代码,上述的两条也会使你的程序慢下来。你是否更倾向于用下面的代码检查一个电子信箱地址呢:
<?php
function validateEmail($email)
{
$hasAtSymbol = strpos($email, "@");
$hasDot = strpos($email, ".");
if($hasAtSymbol && $hasDot)
return true;
else
return false;
}
echo validateEmail("mitchell@devarticles.com");
?>
... 或者使用下面的代码:
<?php
function validateEmail($email)
{
return ereg("^[a-zA-Z]+@[a-zA-Z]+\.[a-zA-Z]+$", $email);
}
echo validateEmail(mitchell@devarticles.com);
?>
可以肯定的是,第一个函数比较容易,而且看起来结构也不错。但是如果我们用上面的下一个版本的email地址检查函数不是更容易吗?
上面展示的第二个函数只用了正则表达式,包括了对ereg函数的一个调用。Ereg 函数返回true或者false,来声明它的字符串参数是否和正则表达式相匹配。
很多编程者避开正则表达式,只因为它们(在一些情况下)比其它的文本处理方法更慢。正则表达式可能慢的原因是因为它 们涉及把字符串在内存中拷贝和粘贴,因为正则表达式的每一个新的部分都对应匹配一个字符串。但是,从我对正则表达式的经验来说,除非你在文本中几百个行运 行一个复杂的正则表达式,否则性能上的缺陷都可以忽略不计,当把正则表达式作为输入数据检查工具时,也很少出现这种情况。
正则表达式语法
在你可以匹配一个字符串到正则表达式之前,你必须先建立正则表达式。开始的时候,正则表达式的语法有点古怪,表达式中的每一个短语代表某个类型的搜索特征。下列是一些最普通的正则表达式,也都对应着一个如何使用它的例子:
字符串头部
搜索一个字符串的头部,用^,例如
<?php echo ereg("^hello", "hello world!"); ?>
将返回 true, 但是
<?php echo ereg("^hello", "i say hello world"); ?>
将返回 false, 因为hello不在字符串”I say hello world”的头部。
字符串尾部
搜索字符串尾部,用$,例如:
<?php echo ereg("bye$", "goodbye"); ?>
将返回true, 但是
<?php echo ereg("bye$", "goodbye my friend"); ?>
将返回 false,因为bye不在字符串”goodbye my friend”的尾部.
任意的单个字符
搜索任意字符,用点(.),例如:
<?php echo ereg(".", "cat"); ?>
将返回true,但是
<?php echo ereg(".", ""); ?>
将返回false,因为我们的要搜索字符串没有包含字符。你可以用花括号随意告诉正则表达式引擎它要匹配多少个单个字符。如果我只想匹配5个字符,我可以这样用ereg:
<?php echo ereg(".{ 5 }$", "12345"); ?>
上面的这段代码告诉正则表达式引擎当且仅当至少5个连续的字符出现字符串的尾部时返回true.我们也可以限制连续出现的字符的数目:
<?php echo ereg("a{ 1,3 }$", "aaa"); ?>
在上面的例子里,我们已经告诉正则表达式引擎,我们的搜索字符串来匹配表达式,它在尾部必须有介于1和3个的”a”字符。
<?php echo ereg("a{ 1,3 }$", "aaab"); ?>
上面的例子将不会返回true,虽然有三个”a”字符在搜索字符串里,但是它们不是在字符串的尾部。如果我们把结尾字符串匹配$从正则表达式中去掉,那么这个字符串是匹配的。
我们也可以告诉正则表达式引擎来匹配至少有确定数目的字符在一行,如果它们存在的,可以匹配更多。 我们可以这样做:
<?php echo ereg("a{ 3, }$", "aaaa"); ?>
零或多次重复字符
为了告诉正则表达式引擎一个字符可能存在,也可以重复,我们用*字符。这里的两个例子都将返回true.
<?php echo ereg("t*", "tom"); ?>
<?php echo ereg("t*", "fom"); ?>
即使第二个例子不包含”t”这个字符,但仍旧返回ture,因为*表示字符可以出现,但不是必须出现。事实上,任何普通的字符串模式都会使上面的ereg调用返回true,因为’t’字符是可选的.
一或多次重复字符
为了告诉正则表达式引擎一个字符必须存在,也可以重复不止一次,我们用+字符,像
<?php echo ereg("z+", "i like the zoo"); ?>
下面的例子也会返回true:
<?php echo ereg("z+", "i like the zzzzzzoo!"); ?>
零或一次重复字符
我们也可以告诉正则表达式引擎,一个字符必须是或者只存在一次,或者没有。我们用?字符来做这项工作,就像
<?php echo ereg("c?", "cats are fuzzy"); ?>
如果我们愿意,我们完全可以从上面的搜索字符串中删除’c’,这个表达式会仍旧返回true.’?’ 的意思是一个’c’可以出现在搜索字符串的任何地方,但不是必须的。
正则表达式语法 (续)
空格字符
为了匹配一个搜索字符串中的空格字符,我们用预定义Posix的类,[[:space]].方括号标明连续字符的相关性,”:space:”是实际要匹配
的类(在这种情形下,是任何空白字符)。空白包括tab字符,新行字符,空白字符。或者,如果搜索字符串必须包含只有一个空格,而不是一个tab或者新行
字符,你可以用一个空格字符("
")。在大多数情况下,我倾向于使用":space:",因为这意味着我的意图不仅仅是单个空格字符,这点很容易被忽视。这里有一些Posix-标准预定
义类,
有一些我们可以作为正则表达式的部分的一些Posix-标准预定义类,包括[:alnum:], [:digit:], [:lower:]等等。 完整的列表可以在这里查看
我们可以像这样匹配单个空白字符:
<?php echo ereg("Mitchell[[:space:]]Harper", "Mitchell Harper"); ?>
我们也可以通过在表达式后用?字符来告诉正则表达式引擎匹配没有空白或者一个空白。
<?php echo ereg("Mitchell[[:space:]]?Harper", "MitchellHarper"); ?>
模式分组
相关的模式可以在方括号里分在一起。很容易用[a-z]和[A-Z]指定只有一个小写字母或者一列大写字母以搜索字符串的一部分存在。
<?php
// 要求从第一个到最后一个都是小写字母
echo ereg("^[a-z]+$", "johndoe"); // 返回true
?>
或者像
<?php
// 要求从第一个到最后一个都是大写字母
ereg("^[A-Z]+$", "JOHNDOE"); // 返回 true?
?>
我们也可以告诉正则表达式引擎,我们希望或者是小写字母,或者是大写字母。我们只要把[a-z]和[A-Z]模式结合在一起就可以做到。
<?php echo ereg("^[a-zA-Z]+$", "JohnDoe"); ?>
在上面的例子里,如果我们能匹配"John Doe",而不是"JohnDoe",将是非常有意义的。我们用下面的正则表达式来做这个:
^[a-zA-Z]+[[:space:]]{ 1 }[a-zA-Z]+$
很容易搜索一个数字字符串
<?php echo ereg("^[0-9]+$", "12345"); ?>
词语分组
不仅仅搜索模式可以分组,我们也可以用圆括号把相关的搜索词语进行分组。
<?php echo ereg("^(John|Jane).+$", "John Doe"); ?>
在上面的例子中,我们有一个字符串头部字符,紧跟着"John"或者"Jane",至少有一个其它字符,然后一个字符串尾部字符。所以…
<?php echo ereg("^(John|Jane).+$", "Jane Doe"); ?>
...将也匹配我们的搜索模式
特殊字符的情形
因为一些字符要用在一个搜索模式的明确分组或者语法上,像在(John|Jane)中的圆括号,我们需要告诉正则表达式引擎来屏蔽这些字符,加工它们使之
成为被搜索字符串的一部分,而不是搜索表达式的一部分。我们所用的方法称为“字符转义”,涉及到将任何“专用符号”加上反斜杠。所以,例如,如果我想在我
的搜索中包含’|’,那么我就可以这样做
<?php echo ereg("^[a-zA-z]+\|[a-zA-z]+$", "John|Jane"); ?>
这里只是少量的一些你要转义的字符,你必须转义^, $, (, ), ., [, |, *, ?, +, \ and { 。
希望你现在对正则表达式实际上有多么强大有了一点点感觉了。现在让我们看两个用正则表达式来检查数据中一个字符串的例子。
正则表达式例子
例子1
让我们把第一个例子做的相当简单,检验一个标准的URL.一个标准的URL(没有端口号),有三个部分构成:
[协议]://[域名]
让我们从匹配URL的协议部分开始,并且让它只能用http或者ftp.我们可以用下面的正则表达式做到这点:
^(http|ftp)
^字符特指字符串的头部,利用圆括号把http和ftp围住,且用“或者”符号(|)将它们分开,我们告诉正则表达式引擎http和ftp两者之一必须在字符串的开头。
一个域名通常由www.somesite.com构成,但是可以随意选择要不要www部分。为了例子简单,我们只允许.com,.net,和.org的域名是在考虑之中的。我们最好这样对正则表达式中的域名部分表示如下:
(www\.)?.+\.(com|net|org)$
把所有的东西放在一起,我们的正则表达式就可以用作检查一个域名,如:
<?php
function isValidDomain($domainName)
{
return ereg("^(http|ftp)://(www\.)?.+\.(com|net|org)$", $domainName);
}
//真(true)
echo isValidDomain("http://www.somesite.com");
//真(true)
echo isValidDomain("ftp://somesite.com");
//假 (false)
echo isValidDomain("ftp://www.somesite.fr");
//假 (false)
echo isValidDomain(www.somesite.com);
?>
例子二
因为我居住在澳大利亚悉尼,让我们检查一个典型的澳大利亚国际电话号码。澳大利亚国际电话号码的格式如下:
+61x xxxx-xxxx
第一个x是区号,其它的都是电话号码。检查以'+61'开头且紧跟一个在2到9之间的区号的电话号码,我们用下面的正则表达式:
^\+61[2-9][[:space:]]
注意,上面的搜索模式把'+'字符用''转义,以便于可以在搜索中包含,不至于被解释为一个正则表达式。[2-9]告诉正则表达式引擎我们需要包含一个2到9之间的数字。[[:space:]]类则告诉正则表达式期望在这里有一个空白。
这里是电话号码剩下的搜索模式:
[0-9]{ 4 }-[0-9]{ 4 }$
这里没有什么不寻常的地方,我们只是告诉正则表达式引擎电话号码可用的数字,它必须是4个数字的组合,跟着一个连接符,再跟着另一个4个数字的组合,然后一个字符串尾部字符。
把完整的正则表达式放在一起,放进一个函数,我们可以用代码来检查一些澳大利亚国际电话号码:
<?php
function isValidPhone($phoneNum)
{
echo ereg("^\+61[2-9][[:space:]][0-9]{ 4 }-[0-9]{ 4 }$", $phoneNum);
}
// 真(true)
echo isValidPhone("+619 0000-0000");
// 假(false)
echo isValidPhone("+61 00000000");
//假( false)
echo isValidPhone("+611 00000000");
?>
<form id="form1" name="form1" method="post" action=""> <input type="text" name="start" /> 到 <input type="text" name="end" /> <input type="submit" name="Submit" value="提交" /> <input type="reset" name="Submit2" value="重置" /> </form>
<?php /* *心若水寒 *http://www.phpfans.net/ */ if(isset($_POST['Submit'])){ $conn = mysql_connect("localhost","root",""); mysql_query("set names 'gbk'"); mysql_select_db("caiji2"); for($i=$_POST['start'];$i<=$_POST['end'];$i++){ $url = "http://www.phper.com/html/php-mysql/".$i.".html"; @$fp = fopen($url,'r'); if(!$fp) continue; $buffer = ''; while(@!feof($fp)){ $buffer .= @fread($fp,1024); } preg_match_all("/<h1>(.+?)</h1>/is",$buffer,$title); $title[0][0] = preg_replace("/<h1>(.+?)</h1>/is","1",$title[0][0]); $title = explode("——",$title[0][0]); $ar_subject = $title[0]; //echo $ar_subject;exit; preg_match_all("/<div class="content">(.+?)</div>/s",$buffer,$array); //echo $array[0][0];exit; //preg_match_all("/(.+)<br>/is",$array[0][0],$array); //$array[0][0] = str_replace("<","<",$array[0][0]);CnPhper.com By Cnphper CnPhperFrom CnPhper.com //$array[0][0] = str_replace(">",">",$array[0][0]); //$array[0][0] = htmlspecialchars($array[0][0]); //$array[0][0] = str_replace("<BR>","n",$array[0][0]); //$array[0][0] = str_replace(" "," ",$array[0][0]); $ar_content = strip_tags($array[0][0],"<br>"); //$ar_content = str_replace("From CnPhper.com","",$ar_content); //$ar_content = preg_replace("/CnPhper.com/i","",$ar_content); //echo $ar_content;exit; //$ar_content = substr($array[0][0],14,-6); $sql = "insert into cdb_article values(null,'未知','".addslashes($ar_subject)."','".addslashes($ar_content)."','互联网','2006-07-20',0,4,0,1,0)"; mysql_query($sql,$conn); fclose($fp); } } ?>
<?php
/**
* 采集百度的搜索结果,可以用到站内搜索,节省资源
* 分页部分就没有处理了,需在函数外处理
*
* @author Aboc QQ:9986584
*/
function searchBaidu($keyword,$page=0){
if(empty($keyword))return false;
$keyword = urlencode($keyword);
if($page>76)$page=76;
$content = file_get_contents("http://www.baidu.com/s?wd=".$keyword.'&pn='.$page);
//echo $content;
//如果找不到
if(strpos($content,'抱歉,没有找到与“<font color="#C60A00">')!==false)return false;
preg_match('/百度一下,找到相关网页(.*)篇,用时/',$content,$a);
//搜索结果数
$num = str_replace(array('约',','),'',$a[1]);
$page = ceil($num)/10;
//echo $num;
//采集到的标题
preg_match_all('/(\<font size=\"3\"\>(.+?)\<\/font\>\<\/a\>\<br\>)/',$content,$b);
//print_r($b[2]);
$title = $b[2];
//采网址
preg_match_all('/(\<a onmousedown=\"(.+?)\" href=\"(.+?)\" target=\"_blank\"\>)/',$content,$c);
//print_r($c);
$href = $c[3];
//采内容
preg_match_all('/(\<font size=-1\>(.+?)\<br\>)/',$content,$d);
//print_r($d);
$detail = $d[2];
$end = array();
$end[0] = array('num'=>ceil($num),'page'=>$page);
foreach( $title as $key=>$row ){
$end[1][$key]['title']=$title[$key];
$end[1][$key]['href']=$href[$key];
$end[1][$key]['detail']=$detail[$key];
}
return $end;
}
/**
* 使用
*/
if( $search = searchBaidu('www.yiwuku.com') )
print_r($search);
else
echo '没有找到';生成:
<?php
define('IN_ECS', true);
require('../includes/init.php');
$id = isset($_GET['id'])?$_GET['id']:'';
$key = isset($_GET['key'])?$_GET['key']:'';
if($key != 'DFDAe' || empty($id))die("错误");
$sql = "select goods_id,goods_sn,goods_name,goods_img,goods_thumb from girls_goods where brand_id=$id";
$rows = $db->getAll($sql);
//print_r($rows);
$doc = new DOMDocument();
$doc->formatOutput = true;
$goods = $doc->createElement('goods');
$doc->appendChild($goods);
foreach ($rows as $row){
$good = $doc->createElement('good');
$goods_id = $doc->createElement('goods_id');
$goods_id2 = $doc->createTextNode($row['goods_id']);
$goods_id->appendChild($goods_id2);
$good->appendChild($goods_id);
$goods_sn = $doc->createElement('goods_sn');
$goods_sn2 = $doc->createTextNode($row['goods_sn']);
$goods_sn->appendChild($goods_sn2);
$good->appendChild($goods_sn);
$goods_name = $doc->createElement('goods_name');
$goods_name2 = $doc->createTextNode($row['goods_name']);
$goods_name->appendChild($goods_name2);
$good->appendChild($goods_name);
$goods_img = $doc->createElement('goods_img');
$goods_img2 = $doc->createTextNode('http://www.togirl.cn/'.$row['goods_img']);
$goods_img->appendChild($goods_img2);
$good->appendChild($goods_img);
$goods_thumb = $doc->createElement('goods_thumb');
$goods_thumb2 = $doc->createTextNode('http://www.togirl.cn/'.$row['goods_thumb']);
$goods_thumb->appendChild($goods_thumb2);
$good->appendChild($goods_thumb);
$goods->appendChild($good);
}
echo $doc->saveXML();
读取到一个数组中
<?php
//header('charset:utf-8');
$doc = new DOMDocument();
$doc->load('http://www.yiwuku.com/xml/brand.php?id=13&key=DFDAe');
$goods = $doc->getElementsByTagName('good');
$newgoods = array();
foreach ($goods as $key=>$good){
$id = $good->getElementsByTagName('goods_id');
$newgoods[$key]['goods_id'] = $id->item(0)->nodeValue;
$sn = $good->getElementsByTagName('goods_sn');
$newgoods[$key]['goods_sn'] = $sn->item(0)->nodeValue;
$name = $good->getElementsByTagName('goods_name');
$newgoods[$key]['goods_name'] = iconv('utf-8','gbk',$name->item(0)->nodeValue);
$img = $good->getElementsByTagName('goods_img');
$newgoods[$key]['goods_img'] = $img->item(0)->nodeValue;
$thumb = $good->getElementsByTagName('goods_thumb');
$newgoods[$key]['goods_thumb'] = $thumb->item(0)->nodeValue;
}
print_r($newgoods);xdebug.profiler_output_dir="c:\php5\xdebug"
参数说明如下:
1.创建虚拟主机
NameVirtualHost 192.168.1.101
<VirtualHost 192.168.1.101>
DocumentRoot "c:/www"
ServerName test.yiwuku.net
</VirtualHost>
<VirtualHost 192.168.1.101>
DocumentRoot "c:/www/w1"
ServerName test1.yiwuku.net
</VirtualHost>
<VirtualHost 192.168.1.101>
DocumentRoot "c:/www/w2"
ServerName test2.yiwuku.net
</VirtualHost>
也可以加上
ErrorLog /var/log/httpd/hr.yourdomain.com/error_log
TransferLog /var/log/hr.yourdomain.com/access_log
2.不能启动,运行-》cmd 进入到apache的bin目录。输入httpd.exe -w -n "Apache" -k start 会提示配置文件的具体那行出错, 其中"Apache"为服务的名字
自己弄了一个,不过好像速度不理想
$badword='坏词一|坏词二'; //用|隔开词
$word=explode('|',$badword);
foreach ( $word as $value ) {
if( strstr(str_replace(array(' ','\n'),array('',''),$form['Detail']),$value) ){
die('有害信息');
}
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
<HTML xml:lang="zn" xmlns="http://www.w3.org/1999/xhtml">
<HEAD>
<TITLE>浮动层居中的对话框效果演示</TITLE>
<META http-equiv=content-type content="application/xhtml+xml; charset=gb2312">
<STYLE type=text/css>
HTML {
HEIGHT: 100%
}
BODY {
HEIGHT: 100%
}
BODY {
FONT-SIZE: 14px; FONT-FAMILY: Tahoma, Verdana, sans-serif
}
DIV.neat-dialog-cont {
Z-INDEX: 98; BACKGROUND: none transparent scroll repeat 0% 0%; LEFT: 0px; WIDTH: 100%; POSITION: absolute; TOP: 0px; HEIGHT: 100%
}
DIV.neat-dialog-bg {
Z-INDEX: -1; FILTER: alpha(opacity=70); LEFT: 0px; WIDTH: 100%; POSITION: absolute; TOP: 0px; HEIGHT: 100%; BACKGROUND-COLOR: #eee; opacity: 0.7
}
DIV.neat-dialog {
BORDER-RIGHT: #444 1px solid; BORDER-TOP: #444 1px solid; Z-INDEX: 99; MARGIN-LEFT: auto; BORDER-LEFT: #444 1px solid; WIDTH: 30%; MARGIN-RIGHT: auto; BORDER-BOTTOM: #444 1px solid; POSITION: relative; TOP: 25%; BACKGROUND-COLOR: #fff
}
DIV.neat-dialog-title {
PADDING-RIGHT: 0.3em; PADDING-LEFT: 0.3em; FONT-SIZE: 0.8em; PADDING-BOTTOM: 0.1em; MARGIN: 0px; LINE-HEIGHT: 1.2em; PADDING-TOP: 0.1em; BORDER-BOTTOM: #444 1px solid; POSITION: relative
}
IMG.nd-cancel {
RIGHT: 0.2em; POSITION: absolute; TOP: 0.2em
}
DIV.neat-dialog P {
PADDING-RIGHT: 0.2em; PADDING-LEFT: 0.2em; PADDING-BOTTOM: 0.2em; PADDING-TOP: 0.2em; TEXT-ALIGN: center
}
</STYLE>
<SCRIPT type=text/javascript>
function NeatDialog(sHTML, sTitle, bCancel)
{
window.neatDialog = null;
this.elt = null;
if (document.createElement && document.getElementById)
{
var dg = document.createElement("div");
dg.className = "neat-dialog";
if (sTitle)
sHTML = '<div class="neat-dialog-title">'+sTitle+
((bCancel)?
'<img src="x.gif" alt="Cancel" class="nd-cancel" />':'')+
'</div>\n' + sHTML;
dg.innerHTML = sHTML;
var dbg = document.createElement("div");
dbg.id = "nd-bdg";
dbg.className = "neat-dialog-bg";
var dgc = document.createElement("div");
dgc.className = "neat-dialog-cont";
dgc.appendChild(dbg);
dgc.appendChild(dg);
//adjust positioning if body has a margin
if (document.body.offsetLeft > 0)
dgc.style.marginLeft = document.body.offsetLeft + "px";
document.body.appendChild(dgc);
if (bCancel) document.getElementById("nd-cancel").onclick = function()
{
window.neatDialog.close();
};
this.elt = dgc;
window.neatDialog = this;
}
}
NeatDialog.prototype.close = function()
{
if (this.elt)
{
this.elt.style.display = "none";
this.elt.parentNode.removeChild(this.elt);
}
window.neatDialog = null;
}
function openDialog()
{
var sHTML = '<p>西西<a target="_blank" href="/" class="wordstyle">WEB开发</a>脚本特效集演示中心,<a href="">国内最大的<a target="_blank" href="/" class="wordstyle">WEB开发</a>资源社区!</p>'+
'<p><button onclick="window.neatDialog.close()">关闭!</button></p>';
new NeatDialog(sHTML, "欢迎光临!", false);
}
</SCRIPT>
<META content="MSHTML 6.00.3790.630" name=GENERATOR></HEAD>
<BODY>
<H1>浮动层居中的对话框效果演示</H1>
<BUTTON onclick=openDialog()>演示层提示效果</BUTTON>
</BODY></HTML>$fin_str = join($br,str_split($str,4));
str_split 将字符串分成相等的几个部分..(新数组)
然后用join 将新数组的值用$br连起来
不过对于含有HTML代码的,这样直接做可能不行,得另外想办法
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
*{margin:0;padding:0;}
</style>
</head>
<body>
<p>测试</p><p>测试</p><p>测试</p><p>测试</p><p>测试</p><p>测试</p><p>测试</p>
<p>测试</p><p>测试</p><p>测试</p><p>测试</p><p>测试</p><p>测试</p><p>测试</p><p>测试</p>
<input type="button" value="点击这里" onclick="sAlert('测试效果<br/>嗯!效果还不错!');" />
<script type="text/javascript" language="javascript">
function sAlert(str){
var msgw,msgh,bordercolor;
msgw=400;//提示窗口的宽度
msgh=100;//提示窗口的高度
titleheight=25 //提示窗口标题高度
bordercolor="#336699";//提示窗口的边框颜色
titlecolor="#99CCFF";//提示窗口的标题颜色
var sWidth,sHeight;
sWidth=document.body.offsetWidth;//浏览器工作区域内页面宽度
sHeight=screen.height;//屏幕高度(垂直分辨率)
//背景层(大小与窗口有效区域相同,即当弹出对话框时,背景显示为放射状透明灰色)
var bgObj=document.createElement("div");//创建一个div对象(背景层)
//定义div属性,即相当于
//<div id="bgDiv" style="position:absolute; top:0; background-color:#777; filter:progid:DXImagesTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75); opacity:0.6; left:0; width:918px; height:768px; z-index:10000;"></div>
bgObj.setAttribute('id','bgDiv');
bgObj.style.position="absolute";
bgObj.style.top="0";
bgObj.style.background="#777";
bgObj.style.filter="progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75";
bgObj.style.opacity="0.6";
bgObj.style.left="0";
bgObj.style.width=sWidth + "px";
bgObj.style.height=sHeight + "px";
bgObj.style.zIndex = "10000";
document.body.appendChild(bgObj);//在body内添加该div对象
var msgObj=document.createElement("div")//创建一个div对象(提示框层)
//定义div属性,即相当于
//<div id="msgDiv" align="center" style="background-color:white; border:1px solid #336699; position:absolute; left:50%; top:50%; font:12px/1.6em Verdana,Geneva,Arial,Helvetica,sans-serif; margin-left:-225px; margin-top:npx; width:400px; height:100px; text-align:center; line-height:25px; z-index:100001;"></div>
msgObj.setAttribute("id","msgDiv");
msgObj.setAttribute("align","center");
msgObj.style.background="white";
msgObj.style.border="1px solid " + bordercolor;
msgObj.style.position = "absolute";
msgObj.style.left = "50%";
msgObj.style.top = "50%";
msgObj.style.font="12px/1.6em Verdana, Geneva, Arial, Helvetica, sans-serif";
msgObj.style.marginLeft = "-225px" ;
msgObj.style.marginTop = -75+document.documentElement.scrollTop+"px";
msgObj.style.width = msgw + "px";
msgObj.style.height =msgh + "px";
msgObj.style.textAlign = "center";
msgObj.style.lineHeight ="25px";
msgObj.style.zIndex = "10001";
var title=document.createElement("h4");//创建一个h4对象(提示框标题栏)
//定义h4的属性,即相当于
//<h4 id="msgTitle" align="right" style="margin:0; padding:3px; background-color:#336699; filter:progid:DXImageTransform.Microsoft.Alpha(startX=20, startY=20, finishX=100, finishY=100,style=1,opacity=75,finishOpacity=100); opacity:0.75; border:1px solid #336699; height:18px; font:12px Verdana,Geneva,Arial,Helvetica,sans-serif; color:white; cursor:pointer;" onclick="">关闭</h4>
title.setAttribute("id","msgTitle");
title.setAttribute("align","right");
title.style.margin="0";
title.style.padding="3px";
title.style.background=bordercolor;
title.style.filter="progid:DXImageTransform.Microsoft.Alpha(startX=20, startY=20, finishX=100, finishY=100,style=1,opacity=75,finishOpacity=100);";
title.style.opacity="0.75";
title.style.border="1px solid " + bordercolor;
title.style.height="18px";
title.style.font="12px Verdana, Geneva, Arial, Helvetica, sans-serif";
title.style.color="white";
title.style.cursor="pointer";
title.innerHTML="关闭";
title.onclick=removeObj;
var button=document.createElement("input");//创建一个input对象(提示框按钮)
//定义input的属性,即相当于
//<input type="button" align="center" style="width:100px; align:center; margin-left:250px; margin-bottom:10px;" value="关闭">
button.setAttribute("type","button");
button.setAttribute("value","关闭");
button.style.width="60px";
button.style.align="center";
button.style.marginLeft="250px";
button.style.marginBottom="10px";
button.style.background=bordercolor;
button.style.border="1px solid "+ bordercolor;
button.style.color="white";
button.onclick=removeObj;
function removeObj(){//点击标题栏触发的事件
document.body.removeChild(bgObj);//删除背景层Div
document.getElementById("msgDiv").removeChild(title);//删除提示框的标题栏
document.body.removeChild(msgObj);//删除提示框层
}
document.body.appendChild(msgObj);//在body内添加提示框div对象msgObj
document.getElementById("msgDiv").appendChild(title);//在提示框div中添加标题栏对象title
var txt=document.createElement("p");//创建一个p对象(提示框提示信息)
//定义p的属性,即相当于
//<p style="margin:1em 0;" id="msgTxt">测试效果</p>
txt.style.margin="1em 0"
txt.setAttribute("id","msgTxt");
txt.innerHTML=str;//来源于函数调用时的参数值
document.getElementById("msgDiv").appendChild(txt);//在提示框div中添加提示信息对象txt
document.getElementById("msgDiv").appendChild(button);//在提示框div中添加按钮对象button
}
</script>
</body>
</html>