dongposhi8677
2014-03-04 19:50
浏览 30
已采纳

如何拉取elseif - preg_match_all

I need advise how to pull content from this string.

$string = "{elseif "xxx"=="xxx"} text {elseif "xx2"!="xx2"}
text text
text
{elseif ....} text";
//or 'xxx'=='xxx'

$regex = "??";
preg_match_all($regex, $string, $out, PREG_SET_ORDER);
var_dump($out);

And my idea of ​​var_dump output is:

array
  0 => 
    array
      0 => string 'xxx' (length=3)
      1 => string '==' (length=2)
      2 => string 'xxx' (length=3)
      3 => string 'text' (length=4)
  1 => 
    array
      1 => string 'xx2' (length=)
      2 => string '!=' (length=)
      3 => string 'xx2' (length=)
      4 => string 'text text
text' (length=)
  2 => 
    array
      ...

The output need not necessarily be as follows, but the same content.

my attempt:

$regex = "~{elseif ([\"\'](.*)[\"\'])(!=|==|===|<=|<|>=|>)([\"\'](.*)[\"\'])}(.*)~sU";

But I have bad or no output content.

1条回答 默认 最新

相关推荐 更多相似问题