php中的正则表达式,用于搜索特定的数据集

searching for i wanted to extract a paragraph from my website . their are more then 20 paragraph tags used in the index page. the key diff. is style18 class is used 1 time and style 19 3 time in each tag. i want to search them with the content os class 18 eg. the main content


<p class="margin">
    <span class="style18">*the main content*</span>
      » <a href="https://example1.html">
        somthing</a>

        <span class="style19">[somthing]</span>
         » <a href="https://example1.html">Town</a>

         <span class="style19">[somthing]</span>
          » <a href="https://example1.html">somthing</a>

    <span class="style19">[somthing]</span> »
    <a href="https://www.example.html">somthing</a>

    <span class="style19">[somthing]</span>

</p>

<?php
  $data = file_get_contents('https://www.example.net/index.php');

  preg_match('/<title>([^<]+)<\/title>/i', $data, $matches);
  $title = $matches[1];

  echo preg_match('/(<p)\s.+
.+(style18).+Single\sTrack(.+)
(.+)
(.+)
(.+)
.+(style19).+
(.+)
(.+)
.+(style19).+
(.+)
(.+)
.+(style19).+
(.+)
(.+)
.+(style19).+

<\/p>/i', $data, $matches);

  $img = $matches[1];

  echo $title."<br>
";
  echo $img;
  ?>

Welcome to the community @Aerro.

If I got your question correctly, you want to extract the inner content of any span surrounded by other spans with certain rules. While this could easily break your fingers with regexp, (tree / graph) query languages like XPath would be a good approach to solve this.

Have a look at e.g. http://php.net/manual/en/simplexmlelement.xpath.php