How can I capture the next value of a search in a php string? [closed]

0

I explain. I am using PDFParser with codeigniter. When uploading an invoice to the system, it rescues all the information of said invoice or text in a variable called content, I want to perform a search within that variable so that it returns me in the number of the invoice. For example: I know that within the text is No., and I want the search to return what comes after that data. How could teachers do it? TT_TT, I've been trying different things for a long time and nothing works.

    
asked by Cesar Espinoza 20.11.2017 в 15:09
source

1 answer

0

I can think of two quite simple ways to extract the information you need, I will take only a fragment of the text.

$x = 'CONTACTO: R.U.T.:76.222.222-1 FACTURA ELECTRONICA Nº18490 S.I.I. - CHILLAN Fecha Ess 5452';
$pos = strpos($x, 'Nº'); // Encuentras la posición donde está el número
$substr = substr($x, $pos+3,strlen($x)); // Recortas la cadena para empezar desde el número que buscas.
$arr = str_split($substr); // Conviertes en array
$num = '';
foreach($arr as $v) // Opción 1
{
    if(is_numeric($v))
    {
        $num .= $v;
    }else{
        break;
    }
}

echo $num."\n"; //18490

$anotherWay= $arr[0].$arr[1].$arr[2].$arr[3].$arr[4]; // Opción 2 si la longitud del número nunca cambia.

echo $anotherWay; //18490

Greetings.

    
answered by 20.11.2017 / 16:52
source