Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/240.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP:获取字符串A和字符串B之间的字符串(需要搜索多个字符串)_Php_Arrays_String - Fatal编程技术网

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];