2016-12-29 77 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);