我需要能够将该字符串中的URL隔离为一个新字符串.同时,URL必须在原始字符串中保持完整.跟随吗?我知道这可能真的很简单,但是它正在杀死我.解决方案类似preg_match('/[a-zA-Z]+:\/\/[0-9a-zA-Z;.\/?:@=_#&%~,+$]+/', $string, $matches); $matches[0]将保存结果.(注意:此正则表达式当然不符合RFC;它可能会提取格式错误的URL(按照规范).请参阅 http://www.faqs.org/rfcs/rfc1738.html ).In PHP, I need to be able to figure out if a string contains a URL. If there is a URL, I need to isolate it as another separate string.For example: "SESAC showin the Love! http://twitpic.com/1uk7fi"I need to be able to isolate the URL in that string into a new string. At the same time the URL needs to be kept intact in the original string. Follow?I know this is probably really simple but it's killing me. 解决方案 Something likepreg_match('/[a-zA-Z]+:\/\/[0-9a-zA-Z;.\/?:@=_#&%~,+$]+/', $string, $matches);$matches[0] will hold the result.(Note: this regex is certainly not RFC compliant; it may fetch malformed (per the spec) URLs. See http://www.faqs.org/rfcs/rfc1738.html). 这篇关于PHP(如果字符串包含URL)将其隔离的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-06 16:52