samoht Posted December 23, 2008 Share Posted December 23, 2008 hello, I know this is easy but I forgot the syntax for just getting the first 2 characters of string (url in my case). can anyone help me? my url value will be numeric, 5 digits, but I only want the first two. So if the url was: mysite.com/clinic/11501 I have already exploded the url path into an array so $path[0] = "clinic" and $path[1] = 11501 How do I get the first 2 characters of $path[1]?? Link to comment https://forums.phpfreaks.com/topic/138256-solved-find-the-first-2-characters-in-a-url/ Share on other sites More sharing options...
timmah1 Posted December 23, 2008 Share Posted December 23, 2008 Wouldn't this work? echo substr("$path[1]",2); Link to comment https://forums.phpfreaks.com/topic/138256-solved-find-the-first-2-characters-in-a-url/#findComment-722840 Share on other sites More sharing options...
samoht Posted December 24, 2008 Author Share Posted December 24, 2008 yes thanks I could not remember that to save my life! except it would be: substr($path[1],0,2); since the first number tells php where to start. Link to comment https://forums.phpfreaks.com/topic/138256-solved-find-the-first-2-characters-in-a-url/#findComment-722843 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.