我是PHP和WordPress的新手,我需要使用WordPress函数download_URL()从离岸网站导入图像。
我的问题是,我的网址看起来像这样:
http://www.test/img/FMR.jpg
但我也有看起来像这样的 URL:
http://www.test/img/FMR.jpg?Qq_0y12h
如果有的话,我可以删除 .extension 之后的所有内容吗?
你可以使用preg_replace,我为你做了这个小例子。
<?php
$url = "http://www.test/img/FMR.jpg?Qq_0y12h";
echo "url = $url'n'n";
$urlFormatted = preg_replace("/'?.*$/", "", $url);
echo "urlFormatted = $urlFormatted'n";
?>