I want to have One part multiline in a regex

<?php
 function bloggerLoop ( $matches ) { print_r ( $matches ) ; }

 $theme = preg_replace_callback(
         "#<b:loop values='data:(.*)' var='(.*)'>(.*?)</b:loop>#i",
         "bloggerLoop", 
         $theme 
         );
?>

This is what I have, but b:loop is more than once in the template and this regex skips all the loops and make one "big" loop, but i only need to have one "part".

What need is:

<b:loop values='data:x' var='x'>MULTILINE</b:loop>

The file what is needed to be parsed is: http://pastebin.com/a3g3G1uE

I hope you can help me with the regex.

Tanks.

-Wesley

有帮助吗?

解决方案

Regex is not the tool for this. HTML tag structure is too complex, for basic Regex, and you should try some HTML DOM library like PHP Simple HTML DOM Parser, to do HTML DOM work.

$html = file_get_html('http://pastebin.com/raw.php?i=a3g3G1uE');
foreach($html->find('b:loop') as $element)
       echo $element->values. '<br>';

Look at my example for your specific case and read documentation.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top