如何使用 php 删除最后一个点后的所有数据?
How to remove all data after last dot using php?
如何使用 php 删除最后一个点后的所有数据?
我测试我的代码。它只是回声 aaa
我要展示aaa.bbb.ccc
我该怎么做?
<?PHP
$test = "aaa.bbb.ccc.gif";
$test = substr($test, 0, strpos($test, "."));
echo $test;
?>
你也可以试试这个 -
$test = "aaa.bbb.ccc.gif";
$temp = explode('.', $test);
unset($temp[count($temp) - 1]);
echo implode('.', $temp);
O/P
aaa.bbb.ccc
strpos — Find the position of the first occurrence of a substring in a string
您需要使用strrpos
strrpos — Find the position of the last occurrence of a substring in a string
$test = "aaa.bbb.ccc.gif";
$test = substr($test, 0, strrpos($test, "."));
echo $test;
O/P
aaa.bbb.ccc
您可以利用pathinfo()
的功能来获取点
之前的所有内容
$str = "aaa.bbb.ccc.gif";
echo pathinfo($str, PATHINFO_FILENAME); // aaa.bbb.ccc
如何使用 php 删除最后一个点后的所有数据?
我测试我的代码。它只是回声 aaa
我要展示aaa.bbb.ccc
我该怎么做?
<?PHP
$test = "aaa.bbb.ccc.gif";
$test = substr($test, 0, strpos($test, "."));
echo $test;
?>
你也可以试试这个 -
$test = "aaa.bbb.ccc.gif";
$temp = explode('.', $test);
unset($temp[count($temp) - 1]);
echo implode('.', $temp);
O/P
aaa.bbb.ccc
strpos — Find the position of the first occurrence of a substring in a string
您需要使用strrpos
strrpos — Find the position of the last occurrence of a substring in a string
$test = "aaa.bbb.ccc.gif";
$test = substr($test, 0, strrpos($test, "."));
echo $test;
O/P
aaa.bbb.ccc
您可以利用pathinfo()
的功能来获取点
$str = "aaa.bbb.ccc.gif";
echo pathinfo($str, PATHINFO_FILENAME); // aaa.bbb.ccc