簡體   English   中英

帶有HTML源代碼的preg_grep

[英]preg_grep with html source

我要提取這行

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

使用

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

從此源代碼

<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]"}

有時代碼有空格,我無法處理

嘗試這個:

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

工作示例: https//regex101.com/r/wM1lB8/2

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM