dsfdsf46465 2017-06-05 11:46
浏览 33
已采纳

Php中的值格式删除caracteres

I have this value :

"24,7 km"

i would like to remove "Km" and get only 24,7 as a float number ! someone know how i could do this ? thanks a lot in advance

here my code actualy :

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);

UPDATE WORKING :

  $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);
  • 写回答

1条回答 默认 最新

  • douhuanqiao5290 2017-06-05 11:51
    关注
    $a = "24,7 km";
    $b = str_replace(" km",'',$a);
    $c = str_replace(",",'.',$b);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 基于作物生长模型下,有限水资源的最大化粮食产量的资源优化模型建立
  • ¥15 生成的QRCode圖片加上下載按鈕
  • ¥15 板材切割优化算法,数学建模,python,lingo
  • ¥15 科来模拟ARP欺骗困惑求解
  • ¥100 iOS开发关于快捷指令截屏后如何将截屏(或从截屏中提取出的文本)回传给本应用并打开指定页面
  • ¥15 unity连接Sqlserver
  • ¥15 图中这种约束条件lingo该怎么表示出来
  • ¥15 VSCode里的Prettier如何实现等式赋值后的对齐效果?
  • ¥15 流式socket文件传输答疑
  • ¥20 keepalive配置业务服务双机单活的方法。业务服务一定是要双机单活的方式