PHP:获取字符串A和字符串B之间的字符串(需要搜索多个字符串)
我有一根大绳子,它是这样的:PHP:获取字符串A和字符串B之间的字符串(需要搜索多个字符串),php,arrays,string,Php,Arrays,String,我有一根大绳子,它是这样的: $string = '<span id="nothread307693965">blabla here is a lot of text blabla<span id="nothread5248574987">blabla even more text<span id="nothread9754541">'; 这就是我被困的地方,请帮帮我 preg_match_all('/nothread([0-9]{5,})/', $stri
$string = '<span id="nothread307693965">blabla here is a lot of text blabla<span id="nothread5248574987">blabla even more text<span id="nothread9754541">';
这就是我被困的地方,请帮帮我
preg_match_all('/nothread([0-9]{5,})/', $string, $matches);
$matches
现在包含您想要的内容。您可以使用字符串函数。但出于提取目的,建议使用简单正则表达式进行最小结构验证:
preg_match_all('/[\s]id="nothread(\d+)"/', $html, $result);
$numbers = $result[1];
\s
表示空格。并且\d+
匹配小数。大括号用于捕获,因为它们是第一个,所以它们的内容将显示在结果数组的索引[1]
中
preg_match_all('/[\s]id="nothread(\d+)"/', $html, $result);
$numbers = $result[1];