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正则表达式字符串和减法部分_Php_Regex - Fatal编程技术网

PHP正则表达式字符串和减法部分

PHP正则表达式字符串和减法部分,php,regex,Php,Regex,我有一个字符串,我需要数字3来执行操作 $string = '<div class="wp-block-column"><!-- wp:block {"ref":3} /--></div>'; 我有一个preg_匹配,可以检测 preg_match('/<!-- wp:block {"ref":[0-9]*} \/-->/',$string) 在不知道前面是什么的情况下,如何从$string中只输出数字3?试试这个-preg_match'/

我有一个字符串,我需要数字3来执行操作

$string  =  '<div class="wp-block-column"><!-- wp:block {"ref":3} /--></div>';
我有一个preg_匹配,可以检测

preg_match('/<!-- wp:block {"ref":[0-9]*} \/-->/',$string)
在不知道前面是什么的情况下,如何从$string中只输出数字3?

试试这个-preg_match'/',$string,$matches

然后使用$matches[1]获取数字

如果preg_匹配“/”,$string,$matches{echo$matches[1];}