質問

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