0

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

José M. Pérez
  • 3,199
  • 22
  • 37
A.H
  • 1
  • 4

1 Answers1

1

Try this:

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

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

William J.
  • 1,574
  • 15
  • 26
  • I reach this "(@include{"(.*)"}*)" its oky on online tester but locally in php still has

    attached

    – A.H Nov 11 '15 at 07:22
  • How are you using it in the PHP code? can you post it? – William J. Nov 11 '15 at 07:24
  • sure , $Source is html file foreach(preg_match('/(@include{"(.*)"}*)/', $Source) as $Tempstring) { print_r( $Tempstring); } – A.H Nov 11 '15 at 07:28
  • preg_match returns an int. You shouldn't use this way. You can do something like: `preg_match('/(?<=\<\w\>)(\s*@include.*)(?=\<\/\w\>)/', $Source, $matches);` then iterate over `$matches` – William J. Nov 11 '15 at 07:35