我是php的初学者,我不知道如何解决这个问题。
我有包含段落和链接的文本文件,这是来自文本文件的示例:
$string = ("Lorem 'Ipsum' is simply: dummy 'http://www.exmplelink1.com/blah/blah/file 1 b.txt' text of the printing 'http://www.exmplelink1.com/blah/blah/file 1 c.txt' and typesetting industry. Lorem Ipsum 'http://www.exmplelink2.com/blah/file.txt' has been, the 'industry's standard'");
请注意,字符串中有很多单引号和两个域名:exmplelink1和exmplelink2
我如何只获得exmplelink1链接(单引号之间的完整链接),在这种情况下有两个链接:
'http://www.exmplelink1.com/blah/blah/file 1 b.txt'
'http://www.exmplelink1.com/blah/blah/file 1 c.txt'
感谢您的帮助 :)
这将使您仅获取exmplelink1,使用file_get_contents以字符串形式读取文件数据,然后使用以下代码获取所需的exmplelink1
$re = "/'http:\\/\\/www\\.exmplelink1.*?'/m";
$str = ("Lorem 'Ipsum' is simply: dummy 'http://www.exmplelink1.com/blah/blah/file 1 b.txt' text of the printing 'http://www.exmplelink1.com/blah/blah/file 1 c.txt' and typesetting industry. Lorem Ipsum 'http://www.exmplelink2.com/blah/file.txt' has been, the 'industry's standard'");
preg_match_all($re, $str, $matches);
echo '<pre>';
print_r($matches);
echo '</pre>';
请参阅正则表达式https://regex101.com/r/gE5uX6/2
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句