PHP 如何去除 URL 中的参数
可以使用 PHP 函数 strtok
:
function clean_image_links($image_links)
{
$result = [];
foreach ($image_links as $link) {
$result[] = strtok($link, '?');
}
return $result;
}
测试:
<?php
$image_links = [
0 => "https://seekoon.com/uploads/images/201701/25/1/dxcDfZsjA0.jpg?imageView2/1/w/1024/h/546"
1 => "https://seekoon.com/uploads/images/201610/19/1/F9kV4goXoU.png?imageView2/1/w/1024/h/546#sff"
];
print_r(clean_image_links($image_links));
结果:
array:2 [▼
0 => "https://seekoon.com/uploads/images/201701/25/1/dxcDfZsjA0.jpg"
1 => "https://seekoon.com/uploads/images/201610/19/1/F9kV4goXoU.png"
]