Finden Sie mithilfe regulärer Ausdrücke mehrere Vorkommen eines Musters
P粉186017651
P粉186017651 2024-02-26 23:27:41
0
1
3577

Ich habe diese Saite bekommen:

if(条件A==值A-AND-条件B==值B-OR-条件C==值C)

Ich möchte ein Array mit:

array(3) {
  [0]=>
  string(...) "conditionA==valueA"
  [1]=>
  string(...) "conditionB==valueB"
  [2]=>
  string(...) "conditionC==valueC"
}

Ich verwende derzeit dieses Muster:

preg_match("/^if\((.+)-(.+)\)/U", $current_step_data_exploded[0], $if_statements);

Aber es erfüllt die dritte Bedingung nicht richtig. Kann mir jemand helfen?

P粉186017651
P粉186017651

Antworte allen(1)
P粉139351297
$string = "if(conditionA==valueA-AND-conditionB==valueB-OR-conditionC==valueC)";
$match = preg_match('/^if\((.+)\)$/', $string, $if);
if ($match) {
  $conditions = preg_split('/\-(AND|OR)\-/', $if[1]);
  print_r($conditions);
} else {
  echo "no matches.";
}
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!