PHP中的值格式删除了滤膜

  • 本文关键字:删除 格式 PHP php
  • 更新时间 :
  • 英文 :


我有这个值:

" 24,7 km"

我想删除" km",只得到24,7作为浮点数!有人知道我该怎么做?预先感谢

在这里我的代码实际:

Route::get('/test', function () {
    $origin = '155 avenue franklin roosevelt 11000 Carcassonne';
    $destination = '36 avenue André Chenier 11300 Limoux';
    $response = GoogleMaps::load('directions')
        ->setParam([
            'origin'          => $origin,
            'destination'     => $destination,
            'mode' => 'driving' ,
            'language' => 'fr',
        ])->get();

   $parsed_json = (json_decode($response));

   $distance = $parsed_json->{'routes'}[0]->{'legs'}[0]->{'distance'}->{'text'};
   dd($distance);

更新工作:

  $parsed_json = (json_decode($response));

        $distance = $parsed_json->{'routes'}[0]->{'legs'}[0]->{'distance'}->{'text'};

        $a = $distance;
        $b = str_replace(" km",'',$a);
        $c = str_replace(",",'.',$b);
        dd($c);
$a = "24,7 km";
$b = str_replace(" km",'',$a);
$c = str_replace(",",'.',$b);

最新更新