PHP常用正则表达式
匹配中文字符的正则表达式
: [\u4e00-\u9fa5]
匹配双字节字符(包括汉字在内)
: ["\x00-\xff]
应用:计算字符串的长度
(一个双字节字符长度计2,ASCII字符计1)
String.prototype.len=function(){return
this.replace(["\x00-\xff]/g,"aa").length;}
匹配空行的正则表达式
: [\s| ]*\r
匹配HTML标记的正则表达式: /<(.*)>.*<\/>|<(.*) \/>/
匹配首尾空格的正则表达式
: ("\s*)|(\s*$)
应用:javascript中没有像vbscript那样的trim函数,我们就可以利用这个表达式来实现,如下:
String.prototype.trim = function() {
return this.replace(/("\s*)|(\s*$)/g, "");
}
利用正则表达式分解和转换IP地址
:
下面是利用正则表达式匹配IP地址,并将IP地址转换成对应数值的javascript程序:
function IP2V(ip) {
re=/(\d+)\.(\d+)\.(\d+)\.(\d+)/g //匹配IP地址的正则表达式
if(re.test(ip)) {
return
RegExp.*Math.pow(255,3))+RegExp.*Math.pow(255,2))+RegExp.*255+RegExp.*1
}
else {
throw new Error("Not a valid IP address!")
}
}
不过上面的程序如果不用正则表达式,而直接用split函数来分解可能更简单,程序如下:
var ip="10.100.20.168"
ip=ip.split(".")
alert("IP值是:"+
(ip[0]*255*255*255+ip[1]*255*255+ip[2]*255+ip[3]*1))
匹配Email地址的正则表达式
: \w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*
匹配网址URL的正则表达式
: http://(
相关文档:
关于PHP的前途(二) (来自本站的消息)
3.2在Windows 95/98/NT/2000上快速安装Apache Web服务器(10秒钟)
在Windows上运行PHP,你需要一个Web服务器,你可以使用微软的IIS,也可以使用免费的Apache 。因为可以通过Apache的安装文件setup.exe进行安装,可以为你节省许多时间。
PHPTtriad是一个包括Apache、PHP、MySQ ......
这是随机选择A0-A3四组数据中其中一组PHP代码:
<?php
$A[0]="QQ:<font color=ff32000>7161283</font>";
$A[1]="E_mail:<font color=ff32000>15018499772@139.com</font>";
$A[2]="手机:<font color=ff32000>15018499772</font>";
$A[3]="MSN:<font color=ff32000>chinaa ......
<?php
class Model_Data_FocusData{
....
public function getData(){...}
}
class Model_Data_IndexData{
....
public function getData(){...}
}
?>
有这么几个类,希望能够自动的根据参数来调用不同的类处理数据。
看调用模块:
<?php
function getData($act){
$class = "Mode ......
it is 21th of May. The Month of PHP Security
(http://www.php-security.org) is still running and we have reached a
vulnerability count of 40 vulnerabilities, which is nearly as much as we
disclosed during the whole Month of PHP Bugs in 2007. However there are
11 more days until the end of May and ......
1.
前言
我使用的主机名为server1.example.com
,ip
地址是192.168.0.100
。这些设置可能与你想要的有所不同,所以你必须在适当的地方修改一下。
2
安装MySQL5
用下列命令安装MySQL
:
yum install mysql mysql-server
然后我们为MySQL
创建系统启动链接(这样的话,MySQL
就会随着系统启动而启动),并启动 ......