如何删除php中的最后一个元素

man*_*ala 1 php

我必须删除字符串中的最后一个元素.我用过rtrim,php但它不起作用.

这是字符串:

 /search/listing.html?vehicle_type=&year=&make_name=&model_name=&loc_type=3&zipcode=641004&distance=100&make_order=ASC
Run Code Online (Sandbox Code Playgroud)

我需要删除"&make_order = ASC"

谁能帮我?

Gla*_*vić 5

$s = '/search/listing.html?vehicle_type=&year=&make_name=&model_name=&loc_type=3&zipcode=641004&distance=100&make_order=ASC';
echo substr($s, 0, strrpos($s, '&'));
Run Code Online (Sandbox Code Playgroud)


编辑:

$url = $base_url.trim( $_SERVER['REQUEST_URI'], "&year_order=".$arr['year_order']."" );
//                                            ^
//                                            |_ replace , with .
Run Code Online (Sandbox Code Playgroud)