PHP RegEx

  • Thread starter Thread starter Deleted member 12738
  • Start date Start date
D

Deleted member 12738

I've some trouble with a regular expression.

PHP:
<span class="syntaxdefault">$search&nbsp;</span><span class="syntaxkeyword">=&nbsp;</span><span class="syntaxdefault">preg_match_all</span><span class="syntaxkeyword">(</span><span class="syntaxstring">"/\{START\(.*\)\}.*\{STOP\(.*\)\}/"</span><span class="syntaxkeyword">,&nbsp;</span><span class="syntaxdefault">$template</span><span class="syntaxkeyword">,&nbsp;</span><span class="syntaxdefault">$loops</span><span class="syntaxkeyword">);&nbsp;</span><span class="syntaxdefault"></span>

Won't activate ($search stays emprt and $loops is an empty array) when this is the $template:
Code:
<p>{$HELLO}</p>
{START(example)} {example->TEST} {STOP(example)} {START(test)} {test->TEST} {STOP(test)} {IF($HELLO==Hello World)}

Any guess why?

Thanks in advance,
Mii
 
All variables except $template are not set yet, and yes, but I placed a print_r($loops); right after that line and it returned an empty array so the problem is there.
 
When I tried it using a PHP example off PHP.net nothing came up.
When I took out: \(.*\)\ it started to show stuff.
Seen below:
Code:
<?php
$html = "{HELLO}";

preg_match_all("/{HELLO}/", $html, $matches, PREG_SET_ORDER);

foreach ($matches as $val) {
    echo "matched: " . $val[0] . "\n";
}
?>

So I don't think it's $loops I think it's:
Code:
\{START\(.*\)\}.*\{STOP\(.*\)\}

Hope that helps.
 
Well, the {$HELLO} isn't what I want.
It's the
Code:
{START(example)} {example->TEST} {STOP(example)} {START(test)} {test->TEST} {STOP(test)}
that should match.

So basically {START(ANYTHING_1)}ANYTHING_2{STOP(ANYTHING_1)} should be what the regular expression should find.
 
Try

PHP:
<span class="syntaxdefault">$search&nbsp;</span><span class="syntaxkeyword">=&nbsp;</span><span class="syntaxdefault">preg_match_all</span><span class="syntaxkeyword">(</span><span class="syntaxstring">"/\{START\(*\)\}*\{STOP\(*\)\}/"</span><span class="syntaxkeyword">,&nbsp;</span><span class="syntaxdefault">$template</span><span class="syntaxkeyword">,&nbsp;</span><span class="syntaxdefault">$loops</span><span class="syntaxkeyword">);&nbsp;&nbsp;</span><span class="syntaxdefault"></span>
 
Didn't work. Thanks for help anyways.

I just tested my RegEx in JavaScipt and it turned true. PHP won't do it tough.
 
If I have problems like you, I go to: irc.phpfreaks.com/?channels=help

There is a person how is really good with RegEx.
 
Thanks, I'll try one more thing tough. I might have found the problem. We'll know by the evening.
 
Mii said:
Didn't work. Thanks for help anyways.

I just tested my RegEx in JavaScipt and it turned true. PHP won't do it tough.

Try this. RegEx is something i should learn more. 🙁
PHP:
<span class="syntaxdefault">$search&nbsp;</span><span class="syntaxkeyword">=&nbsp;</span><span class="syntaxdefault">preg_match_all</span><span class="syntaxkeyword">(</span><span class="syntaxstring">"/\{START\(*\)\}(*)\{STOP\(*\)\}/"</span><span class="syntaxkeyword">,&nbsp;</span><span class="syntaxdefault">$template</span><span class="syntaxkeyword">,&nbsp;</span><span class="syntaxdefault">$loops</span><span class="syntaxkeyword">);&nbsp;&nbsp;&nbsp;</span><span class="syntaxdefault"></span>

if it doesn't work, try phpfreaks like ItsBrad said. 🙂
 
Ok, I'll try later today, I'm working on something else now.

Thanks for your help!
 
Back
Top Bottom