简体   繁体   English

PHP:如何正则表达式替换以下字符串?

[英]php: how to regex replace the following strings?

would like to replace all occurence of, double quote included 想替换所有出现的情况,包括双引号

"http://somebunchofchar"

to

"link"

I came up with preg_replace("/\\"http:\\/\\/.\\"/i", "\\"link\\"", $string); 我想出了preg_replace("/\\"http:\\/\\/.\\"/i", "\\"link\\"", $string);

只需在点后添加星号和问号

preg_replace("/\\"http:\\/\\/.*?\\"/i", "\\"link\\"", $string);

$string = preg_replace('#"http://.+"#', '"link"', $string);

您可以使用:

preg_replace('~"http://[^"]*"~i', '"link"', $string);

Just look here: http://regexlib.com/DisplayPatterns.aspx?cattabindex=1&categoryId=2&AspxAutoDetectCookieSupport=1 how to match an URL with the correct pattern; 只需看这里: http : //regexlib.com/DisplayPatterns.aspx ?cattabindex=1&categoryId=2& AspxAutoDetectCookieSupport=1如何将URL与正确的模式进行匹配; than use preg_replace with the particular regexp pattern ;-) (you can add those quotes at the start and end to the pattern yourself quite easily) :-) 而不是将preg_replace与特定的regexp模式一起使用;-)(您可以很容易地在模式的开始和结束处添加这些引号):-)

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

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