繁体   English   中英

php正则表达式在字符串中查找单词

[英]php regex find word in string

PHP正则表达式在我想找到的字符串中找到特定的url

stackoverflow.site

'stackoverflow.site' 在我的字符串中。 稍后我将替换为我自己的网址

$string='Regular expressions are a powerful tool for examining http://www.stackoverflow.site/uploads/2008/07/22/feldbalz-by-gus-wustemann-17.jpg and modifying text. Regular expressions themselves, with a general pattern notation almost like a mini programming language, allow you to describe and parse text. They enable you to search for patterns within a string, extracting matches http://www.stackoverflow.site/uploads/2008/07/22/feldbalz-by-gus-wustemann-squ1.jpg flexibly and precisely. However, you should note that because regular expressions are more powerful, they are also slower than the more basic string functions. You should only use regular expressions if you have http://www.stackoverflow.site/uploads/2008/07/22/feldbalz-by-gus-wustemann-12.jpg a particular need.
This tutorial gives a brief overview of http://www.stackoverflow.site/uploads/2008/07/22/feldbalz-by-gus-wustemann-2.jpg basic regular expression syntax and then considers the functions that PHP provides for working with regular expressions.';

$find='[http://www.stackoverflow.site/uploads/]';

使用preg_quote自动转义正则表达式中的特殊字符

$find='http://www.stackoverflow.site/uploads/';
$rfind=preg_quote($find);
preg_replace($rfind, "mysite", $input_lines);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM