Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/256.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 preg_match我如何提取这个?_Php_Regex - Fatal编程技术网

Php preg_match我如何提取这个?

Php preg_match我如何提取这个?,php,regex,Php,Regex,如何编写正则表达式以从以下内容中提取“所需文本”: data-zoom-image="desired text" 试试这个。 这是一个模式执行此操作不需要预匹配 简单地说,您可以使用 无配额: substr($text, strpos($text, '"')+1, strrpos($text, '"') - strpos($text, '"')-1) ; $str='data zoom image=“所需文本”; preg_match('/data zoom image=“(?P\w+)/”

如何编写正则表达式以从以下内容中提取“所需文本”:

data-zoom-image="desired text"
试试这个。
这是一个模式

执行此操作不需要
预匹配

简单地说,您可以使用

无配额:

substr($text, strpos($text, '"')+1, strrpos($text, '"') - strpos($text, '"')-1) ;
$str='data zoom image=“所需文本”;
preg_match('/data zoom image=“(?P\w+)/”,$str,$matches);
打印(匹配项);

ref:

也许你想看看这里:也许这能帮你
$find = substr($yourString,strpos($yourString,"="));
substr($text, strpos($text, '"')+1, strrpos($text, '"') - strpos($text, '"')-1) ;
$str  = 'data-zoom-image="desired text"';

preg_match('/data-zoom-image="(?P<text>\w+)"/', $str, $matches);

print_r($matches);