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

android - net_scheduler holding wakelock -

sql - MySQL : Getting Entries from a many-to-many table -

java - Retrieving data from database using jsp (Hibernate + Spring + Maven) -