php中是否有一个函数可以搜索字符串,并根据其位于两个定义的字符集之间来查找子字符串?
我正在尝试使用php脚本搜索一些文件,并从中获取一个字符串。
我需要的字符串是一个URL,每个文件都有一个字符串,看起来像这样,中有一个不同的URL
/A << /URI (https://www.website/custom_ url_per_file)
/S /URI >> //an actual linebreak in the code
我在foreach循环中打开了所有文件,那么我如何提取两个字符串$a和$b之间的url?
$a = /A << /URI
$b = /S /URI >>
<?php
$string = '/A << /URI (https://www.website/custom_ url_per_file)
/S /URI >> //an actual linebreak in the code';
preg_match('#/A << /URI '(([^')]+)')'s+'/S /URI >>#', $string, $matches);
print_r($matches);
?>
将导致:
Array
(
[0] => /A << /URI (https://www.website/custom_ url_per_file)
/S /URI >>
[1] => https://www.website/custom_ url_per_file
)