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
Post a Comment