substr - How to remove all data after last dot using php? -


how remove data after last dot using php ?

i test code. it's echo aaa

i want show aaa.bbb.ccc

how can ?

<?php $test = "aaa.bbb.ccc.gif"; $test = substr($test, 0, strpos($test, ".")); echo $test; ?> 

you can try -

$test = "aaa.bbb.ccc.gif";  $temp = explode('.', $test);  unset($temp[count($temp) - 1]);  echo implode('.', $temp); 

o/p

aaa.bbb.ccc 

strpos — find position of first occurrence of substring in string

you need use strrpos

strrpos — find position of last occurrence of substring in string

$test = "aaa.bbb.ccc.gif"; $test = substr($test, 0, strrpos($test, ".")); echo $test; 

o/p

aaa.bbb.ccc 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -