Cut string from end to specific char in php -


i know how can cut string in php starting last character -> specific character. lets have following link:

www.whatever.com/url/otherurl/2535834 

and want 2535834

important note: number can have different length, why want cut out / no matter how many numbers there are.

thanks

in special case, url, use basename() :

echo basename('www.whatever.com/url/otherurl/2535834'); 

a more general solution preg_replace(), this:

                       <----- delimiter separates search string remaining part of string echo preg_replace('#.*/#', '', $url); 

the pattern '#.*/#' makes usage of default greediness of pcre regex engine - meaning match many chars possible , therefore consume /abc/123/xyz/ instead of /abc/ when matching pattern.


Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -