解析HTML块的特定部分

时间:2018-05-24 23:23:09

标签: php regex parsing

我从一个看起来像这样的网站中提取HTML块

<strong>Suggested use:</strong> 
"This is the suggested use text"
<br><br>
<strong>Warning:</strong> 
"This is the warning text"

我正在尝试仅为建议的使用块下的文本和警告块下的文本提取值,并将它们存储在2个单独的字段中。我很难搞清楚如何解析这个问题。有人有任何想法吗?

1 个答案:

答案 0 :(得分:-1)

我看到你将此标记为正则表达式:

$str  = '<strong>Suggested use:</strong> "This is the suggested us text" <br><br> <strong>Warning:</strong> "This is the warning text"';

if (preg_match_all('/"([^"]+)"/', $str, $m)) 
    print_r($m[0]);  

输出: Array ( [0] => "This is the suggested use text" [1] => "This is the warning text" )

另外,如果您不想使用引号:print_r($ m [1]);

编辑:我以为我在PHP部分,所以假设它是php正则表达式,一些澄清会很棒。