Ik wil een variable array automatisch laten parsen in een tabel.
HTLM:
{#var1>var2>var3}
{#>empty}inside empty{#>empty}
before
{#>firstrow}inside firstrow{#>firstrow}
{#>row}inside row{#>row}
{#>lastrow}inside lastrow{#>lastrow}
after
{#}
PHP:
$text = preg_replace_callback('/\{(#+)([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)((?:\>[a-zA-Z0-9_\x7f-\xff]*)*)\}\s*(\{\\1\>empty\}\s*(.*?)\s*\{\\1\>empty\})?\s*(.*?)\s*(\{\\1\>firstrow\}\s*(.*?)\s*\{\\1\>firstrow\})?\s*(\{\\1\>row\}\s*(.*?)\s*\{\\1\>row\})?\s*(\{\\1\>lastrow\}\s*(.*?)\s*\{\\1\>lastrow\})?\s*(.*?)\s*\{\\1\}/s', array('parse', 'replace_array'), $text);
Als ik een print_r doe van $matches in de functie replace_array dan krijg ik volgende resultaat:
Array (
[0] => {#var1>var2>var3} ... {#} (hele string)
[1] => #
[2] => var1
[3] => >var2>var3
[4] => {#>empty}inside empty{#>empty}
[5] => inside empty
[6] =>
[7] =>
[8] =>
[9] =>
[10] =>
[11] =>
[12] =>
[13] => before {#>firstrow}inside firstrow{#>firstrow} {#>row}inside row{#>row} {#>lastrow}inside lastrow{#>lastrow} after
)
Als ik echter uit de html enkel de "before" wegdoe, dan krijg ik wel een correct resultaat terug. Ik vind maar niet waarom die tekst die normaal gematched moet worden met (.*?) de regular expression om zeep helpt en alles laat matches door de laatste (.*?)...
Iemand een idee?