php中包含regular expression的字符串操作函数怎么用?
Getting the domain name out of a URL
<?php
// get host name from URL
preg_match("/^(http:\/\/)?([^\/]+)/i",
"http://www.php.net/index.html", $matches);
$host = $matches[2];
// get last two segments of host name
preg_match("/[^\.\/]+\.[^\.\/]+$/", $host, $matches);
echo "domain name is: {$matches[0]}\n";
?>
This example will produce:
domain name is: php.net
////////////////////////////////
上面例子真有趣,还有很多regular expression的函数,一串/[^\.\/]+\.[^\.\/]+$/。。。。。。。。这样的东西怎么使用呢?
谢谢!
<?php
// get host name from URL
preg_match("/^(http:\/\/)?([^\/]+)/i",
"http://www.php.net/index.html", $matches);
$host = $matches[2];
// get last two segments of host name
preg_match("/[^\.\/]+\.[^\.\/]+$/", $host, $matches);
echo "domain name is: {$matches[0]}\n";
?>
This example will produce:
domain name is: php.net
////////////////////////////////
上面例子真有趣,还有很多regular expression的函数,一串/[^\.\/]+\.[^\.\/]+$/。。。。。。。。这样的东西怎么使用呢?
谢谢!
...全文
相关推荐
PHP 正则获取字符串的URL
在IT行业中,正则表达式(Regular Expression)是一种强大的文本处理工具,广泛应用于字符串匹配、查找、替换等操作。
php使用正则表达式进行字符串搜索的方法
在PHP编程中,正则表达式(Regular Expression)是一种强大的文本处理工具,它允许程序员以灵活的方式进行字符串的搜索、替换和分析。
php代码-在线 php 正则表达式在线测试,php正则测试,在线php正则匹配
正则表达式(Regular Expression)是编程中用于处理文本的强大工具,它可以帮助我们进行复杂的字符串匹配、查找、替换等操作。
php代码-PHP正则表达式
正则表达式(Regular Expression)是一种特殊的字符串模式,用于在文本中搜索、替换或提取符合特定规则的字符串。
php使用正则验证中文
在php中,正则表达式可以使用函数preg_match()、preg_match_all()等来执行匹配操作。在php中验证字符串中是否包含中文,可以使用特定的Unicode范围。


基础编程
