简体   繁体   中英

preg match in php to get data between html

I have the following html code

<pre 
 class="glossaryProduct">
   data goes here
 </pre>

and i need to pull just the "data goes here" between the pre and /pre. Can someone explain how this is done using preg_match?

Thanks

In your simple case the "preg_match" approach would look as below:

$content = '<pre 
 class="glossaryProduct">
   data goes here<br>
   and here
 </pre>';

preg_match("/<pre[^>]*?>(.*)<\/pre>/s", $content, $matches);
$result = $matches[1];
// now the $result contains the needed data

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM