php - RegEx for matching a HTML string
760
I'm trying to do apreg_match_all
, which does not work.
preg_match_all(
'!<div itemprop="description"><p><span ><span ><span >(.*?)</span></span></span></p></div>!',
$html,
$matches1,
PREG_SET_ORDER
);
foreach ($matches1 as $soge2){print_r($soge2);}
How do I make it work?
Answer
Solution:
It may not be the best idea to parse HTMLs with RegEx, which seems that you may want to do. However, based on your question, I'm guessing that you may wish to get all data from this tag using (.*):
It is possible to do so. First, you may design your
preg_match_all();
based on:which in this case, your subject is your HTML input, and I'm not sure, but your pattern might be:
Code
Output
Pattern
You may use a tool to design your desired pattern, such as: