PHP 移除 URL 中的参数

PHP

可以使用 PHP 函数 strtok

function clean_image_links($image_links)
{
    $result = [];
    foreach ($image_links as $link) {
        $result[] = strtok($link, '?');
    }
    return $result;
}

测试:

<?php
$image_links = [
    0 => "https://dn-phphub.qbox.me/uploads/images/201701/25/1/dxcDfZsjA0.jpg?imageView2/1/w/1024/h/546"
    1 => "https://dn-phphub.qbox.me/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://dn-phphub.qbox.me/uploads/images/201701/25/1/dxcDfZsjA0.jpg"
  1 => "https://dn-phphub.qbox.me/uploads/images/201610/19/1/F9kV4goXoU.png"
]
评论数量: 0

1
点赞
558
浏览
0
评论

贡献 538
Summer
Building Products Users Love