2016-12-29 82 views
-1

将表达对preg_match_all怎么得到这个字符串的内容部分:的Preg匹配正则表达式

< meta itemprop="url" content="whatever content is here" > 

到目前为止,我曾尝试:

preg_match_all('| < meta itemprop=/"url/" content=/"(.*?)/" > |',$input,$outputArray); 

回答

0

试试这个表达式:

<?php 
$input = '< meta itemprop="url" content="whatever content is here" >'; 
preg_match_all('/content="(.*?)"/',$input,$outputArray); 
print_r($outputArray); 
?> 

输出

Array 
(
    [0] => Array 
     (
      [0] => content="whatever content is here" 
     ) 

    [1] => Array 
     (
      [0] => whatever content is here 
     ) 
) 

Working Demo

编辑

如果你想获取正则表达式只itemprop="url"内容,修改到

preg_match_all('/itemprop="url".*content="(.*?)"/',$input,$outputArray);