-5

I'm trying to do a preg_match_all, which does not work.

preg_match_all(
    '!<div class="Description_Productinfo" itemprop="description"><p><span style="color:#7f8c8d;"><span style="font-family:Arial,Helvetica,sans-serif;"><span style="font-size:14px;">(.*?)</span></span></span></p></div>!',
    $html,
    $matches1,
    PREG_SET_ORDER
);
foreach ($matches1 as $soge2){print_r($soge2);}

How do I make it work?

Emma
  • 27,428
  • 11
  • 44
  • 69
landsten
  • 1
  • 1
  • someone who can help so I can get the code in to start with? – landsten Apr 28 '19 at 14:16
  • preg_match_all('!

    (.*?)

    !',$html, $matches1, PREG_SET_ORDER); foreach ($matches1 as $soge2){ print_r($soge2); }
    – landsten Apr 28 '19 at 14:16
  • 2
    please **edit** your question so a) your code is formatted and b) it's clear _what_ you want to achieve. right now it's not really understandable. ask yourself: would *you* know what this question is about if someone else asked *you*? – Franz Gleichmann Apr 28 '19 at 14:17
  • 2
    [You shouldn't parse HTML with regex](https://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags). – ggorlen Apr 28 '19 at 14:29

1 Answers1

1

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 (.*):

<span style="font-size:14px;"></span>

It is possible to do so. First, you may design your preg_match_all(); based on:

preg_match_all($pattern, $subject, $matches);

which in this case, your subject is your HTML input, and I'm not sure, but your pattern might be:

/<span style=\"font-size:14px;\">([\w\s]+)(<\/span>)/s 

Code

$html = '<div class="Description_Productinfo" itemprop="description"><p><span style="color:#7f8c8d;"><span style="font-family:Arial,Helvetica,sans-serif;"><span style="font-size:14px;">Alphanumeric Words If You Wish To Match</span></span></span></p></div>';

preg_match_all('/<span style=\"font-size:14px;\">([\w\s]+)(<\/span>)/s', $html, $matches1, PREG_SET_ORDER);
var_dump($matches1);

foreach ($matches1 as $soge2) {
    print_r($soge2);
}

Output

Array
(
    [0] => <span style="font-size:14px;">Alphanumeric Words If You Wish To Match</span>
    [1] => Alphanumeric Words If You Wish To Match
    [2] => </span>
)

Pattern

You may use a tool to design your desired pattern, such as:

enter image description here

Emma
  • 27,428
  • 11
  • 44
  • 69