hi php-coders
i trie to parse some information out of an string with preg_match_all, but
the regex doesn't work (under perl it works perfect)
in the text there a spezial vars with this definition
{[var:]name[#comment][=const]}
[] means 0 or 1 time in the var
my php-programm looks like this
// ************************************************************************
$str = "hallo du {var:name} und du {age} oder
du {point#info} und {test=checked}
du {freak=selected#comment} oder auch
so {freak#comment=selected}";
// i use the same regex like in my perl-program
preg_match_all('/{(var🙂?([A-Za-z0-9_.]+?)(=([#]?))?(#([=]?))?}/msi',$b
uffer,$result);
for($var=0;$var<count($result[0]);$var++){
echo("1:".$result[1][$var]."<br>");
echo("2:".$result[2][$var]."<br>");
echo("3:".$result[3][$var]."<br>");
echo("4:".$result[4][$var]."<br>");
echo("5:".$result[5][$var]."<br>");
echo("6:".$result[6][$var]."<br>");
echo("7:".$result[7][$var]."<br><br>");
}
// ************************************************************************
this is the output:
1:var:
2:name
3:
4:
5:#comment
6:comment
7:
1:
2:age
3:=checked
4:checked
5:#comment
6:comment
7:
1:
2:point
3:=selected
4:selected
5:
6:
7:
1:
2:test
3:
4:
5:
6:
7:
1:
2:freak
3:
4:
5:
6:
7:
and this is my (working) perl-program:
************************************************************************
$str = <<"ENDE";
hallo du {var:name} und du {age} oder
du {point#info} und {test=checked}
du {freak=selected#comment} oder auch
so {freak#comment=selected}
ENDE
while($str =~ /{(var🙂?([A-Za-z0-9_.]+?)(=([#]?))?(#([=]?))?}/msig) {
print "1: $1\n";
print "2: $2\n";
print "3: $3\n";
print "4: $4\n";
print "5: $5\n";
print "6: $6\n";
print "7: $7\n\n";
}
************************************************************************
this is the ouput:
1: var:
2: var
3: name
4:
5:
6:
7:
1:
2:
3: age
4:
5:
6:
7:
1:
2:
3: point
4:
5:
6: #info
7: info
1:
2:
3: test
4: =checked
5: checked
6:
7:
1:
2:
3: freak
4: =selected
5: selected
6: #comment
7: comment
PERFEK!
what is wrong with the preg_match_all regex in my php-programm, why is the
output different
can anyone help me with this problem?
ciao dennis (from germany)