15个实用的PHP正则表达式
发布时间:2020-05-25 07:45:10 所属栏目:PHP 来源:互联网
导读:15个实用的PHP正则表达式
|
下面是脚本之家 jb51.cc 通过网络收集整理的代码片段。 脚本之家小编现在分享给大家,也给大家做个参考。 原文出处: 5iDev$url = "http://komunitasweb.com/";
if (preg_match('/^(http|https|ftp)://([A-Z0-9][A-Z0-9_-]*(?:.[A-Z0-9][A-Z0-9_-]*)+):?(d+)?/?/i',$url)) {
echo "Your url is ok.";
} else {
echo "Wrong url.";
}
$text = "Sample sentence from KomunitasWeb,regex has become popular in web programming. Now we learn regex. According to wikipedia,Regular expressions (abbreviated as regex or
regexp,with plural forms regexes,regexps,or regexen) are written in a formal language that can be interpreted by a regular expression processor";
$text = preg_replace("/b(regex)b/i",'<span style="background:#5fc9f6">1</span>',$text);
echo $text;
echo $title;
Now,just before the modified line,add this code:
<?php
$title = get_the_title();
$keys= explode(" ",$s);
$title = preg_replace('/('.implode('|',$keys) .')/iu','<strong> |
