简体   繁体   中英

preg_grep with html source

I want extract this line

<p>@include{"portal.shared.blook"}</p>

using

preg_grep("/(\s*@include.*)/",explode("\n", $Source)) 

from this source code

<html>
   <head>
        <title>hi</title>
   </head>
   <body>
        <h1>Hi I am layout</h1>
        <br>
        <p>@include{"portal.shared.blook"}</p>
        @require{"portal.shared.footer":"[main]"}

Some times the code has whitespace and I can not handle it

Try this:

(?<=\<\w\>)(\s*@include.*)(?=\<\/\w\>)

Working example: https://regex101.com/r/wM1lB8/2

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