php中的正则表达式的使用
来源:互联网 发布:cf卡测速软件 编辑:程序博客网 时间:2024/06/04 05:16
正则表达式:
preg_match()和preg_match_all()preg_quote()
preg_split()
preg_grep()
preg_replace()
替换HTML源码中的地址
$form_html = preg_replace ( '/(?<=\saction=\" \ssrc=\" \shref=\")(?!http: javascript)(.*?)(?=\"\s)/e', 'add_url(\$url, \'\\1\')', $form_html );
带断言的正则匹配
$match = '';
$str = 'xxxxxx.com.cn bold font paragraph text ';
preg_match_all ( '/(?<=<(\w{1})>).*(?=<\/\1>)/', $str, $match );
echo "匹配没有属性的HTML标签中的内容:";
print_r ( $match );
在正则中使用回调函数
/** * replace some string by callback function * */
function callback_replace() {
$url = 'http://esfang.house.sina.com.cn';
$str = '';
$str = preg_replace ( '/(?<=\saction=\")(?!http:)(.*?)(?=\"\s)/e', 'search(\$url, \\1)', $str );
echo $str;
}
function search($url, $match){
return $url . '/' . $match;
}
匹配action属性
$str = '';
$match = '';
preg_match_all('/\s+action=\"(?!http:)(.*?)\"\s/', $str, $match);
print_r($match);
- php中的正则表达式的使用
- php正则表达式中的非贪婪模式匹配的使用
- PHP 正则表达式的使用
- PHP中的正则表达式
- PHP中的正则表达式
- PHP 中的正则表达式
- php中的正则表达式
- PHP中的正则表达式
- PHP 中的正则表达式
- php中的正则表达式
- php中的正则表达式
- PHP中的正则表达式
- PHP中的正则表达式
- php中的正则表达式
- PHP中的正则表达式
- php中的正则表达式的逆向引用
- PHP中的正则表达式的优化
- PHP第九课 正则表达式在PHP中的使用
- IOS利用AVPlayer开发多媒体在线播放器
- node.js express性能优化
- DeepLearning资源整理
- warning:performSelector may cause a leak because its selector is unknown
- 公有、私有、保护继承的区别
- php中的正则表达式的使用
- Prim、Kruskal、Prim+Heap算法效率实测
- Android使用TextView的onClick不触发解决方案
- 用newLISP读取Hive的元数据
- 杂谈
- Linux/Unix分配进程ID的方法以及源码实现
- 中科院自动化所考博资料收集
- 反素数The Most Complex Number 搜索+剪枝
- 温故知新之进程间通讯技术(IPC)