fork download
  1. <?php
  2. $reg = "/^[A-Z]{2,3}[\d]{3}$/";
  3. $string1 = "USA097 WO : SWAP DE GABINETE";
  4. $string2 = "WO : SWAP DE AV222 GABINETE";
  5. $array1 = explode(" ", $string1);
  6. $array2 = explode(" ", $string2);
  7.  
  8. foreach($array1 as $cadena){
  9. if(preg_match($reg, $cadena)){
  10. $objetivo = $cadena;
  11. break;
  12. }
  13. }
  14. echo strlen($objetivo) ? $objetivo : "No se encontrĂ³ la cadena";
  15.  
  16. echo "\r\n";
  17.  
  18. foreach($array2 as $cadena){
  19. if(preg_match($reg, $cadena)){
  20. $objetivo = $cadena;
  21. break;
  22. }
  23. }
  24. echo strlen($objetivo) ? $objetivo : "No se encontrĂ³ la cadena";
Success #stdin #stdout 0.01s 20520KB
stdin
Standard input is empty
stdout
USA097
AV222