我在 php 中有一个这样的 url 字符串:
$string = 'test.xyz/builder-list/?price=301-500%2C501-1000&builder_country=6442%2C6780%2C6441';
我想从price以 `%2c 开头的 URL 字符串中的查询值中删除特定字符串。例如:
test.xyz/builder-list/?price=301-500%2C501-1000&builder_country=6442%2C6780%2C6441
into
test.xyz/builder-list/?price=301-500&builder_country=6442%2C6780%2C6441
test.xyz/builder-list/?price=-200%2C400-500&builder_region=1223%2C3445
into
test.xyz/builder-list/?price=-200&builder_region=12%2C33
test.xyz/builder-list/?builder_state=45%2C76&price=-200%2C400-500
into
test.xyz/builder-list/?builder_state=45%2C76&price=-200
我尝试使用这个preg_replace函数,但它删除了所有的%2C字符串
preg_replace('/' . preg_quote('%2C') . '.*?/', '', $string);
慕码人2483693
慕桂英3389331
郎朗坤