Ver Mensaje Individual
  #4 (permalink)  
Antiguo 17/03/2013, 11:27
cachusan
 
Fecha de Ingreso: septiembre-2011
Mensajes: 219
Antigüedad: 12 años, 7 meses
Puntos: 31
Respuesta: Determinar la posición que ocupa un número dentro de una cadena de caracte

Aca te dejo una función que te guarda el valor y la posición

Código PHP:
Ver original
  1. <?php
  2.  
  3. /**
  4.  *
  5.  */
  6. function search_numbers($text){
  7.     preg_match_all('!\d+!', $text, $matches);
  8.     $result = array();
  9.     if(@$matches){
  10.         foreach($matches as $match){
  11.             foreach($match as $k => $value){
  12.                 $result[$k]['value'] = $value;
  13.                 $result[$k]['position'] = strpos($text, $value);
  14.             }
  15.         }
  16.     }
  17.     return $result;
  18. }
  19.  
  20. $text = 'Piso123Plaza456';
  21. $resultado =  search_numbers($text);
  22. echo "<pre>";
  23. print_r($resultado);
  24. ?>