help with regular PHP expression

0

I have the following code:

$tiempo=  shell_exec(" curl -o /dev/null -w 'Conexión: %{time_connect} FB: % {time_starttransfer} Tiempo Total: %{time_total} \n' " . $dominio);
echo "<br>";
    echo "Tiempos de carga: ". $tiempo;
    $conexion=;
    $FB=;
    $TTotal=;

But I need a regular expression that puts every number of the variable $tiempo in each variable, it takes it out with the following format:

  

Connection: 0.000 FB: 0.000 Total Time: 0.060

And I'm trying something similar to a regular expression like this:

\FB: [0-9]

But it does not work properly for me, if someone can help me out. Thanks.

    
asked by pablo 07.06.2018 в 20:43
source

1 answer

0

I would suggest read a bit more about how regular expressions work , such as the quantifiers + that allows you to match more than one character of the same type.

This should be able to work:

<?php

$texto = "Conexión: 0.000 FB: 0.000 Tiempo Total: 0.060";

preg_match("/Conexión:\s(\d+\.\d+)/", $texto, $matches_time_connect);
$time_connect = $matches_time_connect[1];

echo "Primer Match: " . $matches_time_connect[0] . " | Valor: " . $time_connect . "<br/>";


preg_match("/FB:\s(\d+\.\d+)/", $texto, $matches_time_starttransfer);
$time_starttransfer = $matches_time_starttransfer[1];

echo "Segundo Match: " . $matches_time_starttransfer[0] . " | Valor: " . $time_starttransfer . "<br/>";


preg_match("/Total:\s(\d+\.\d+)/", $texto, $matches_time_total);
$time_total = $matches_time_total[1];

echo "Tercer Match: " . $matches_time_total[0] . " | Valor: " . $time_total . "<br/>";

?>

This answers with

  

First Match: Connection: 0.000 | Value: 0.000

     

Second Match: FB: 0.000 | Value: 0.000

     

Third Match: Total: 0.060 | Value: 0.060

    
answered by 07.06.2018 / 21:03
source