Rottingham Posted April 27, 2010 Share Posted April 27, 2010 Ok So I want the pro way to do this. I have a string that I just want to pick the first six characters out. My string looks like CEE500 - Open I just want the CEE500. Now I know this is like 'duh'... But, I've tried split ('-', $string) and it returns the whole string, I've tried preg_split('/ /', $string) and I get the whole string. I could do $string=$string[0].$string[1]...$string[5] but that' a lousy way... Any suggestion? Link to comment https://forums.phpfreaks.com/topic/199950-capturing-first-6-characters-in-a-string/ Share on other sites More sharing options...
teamatomic Posted April 27, 2010 Share Posted April 27, 2010 $str='CEE500 - Open'; $string=substr("$str", 0, 6); HTH Teamatomic Link to comment https://forums.phpfreaks.com/topic/199950-capturing-first-6-characters-in-a-string/#findComment-1049457 Share on other sites More sharing options...
Ken2k7 Posted April 27, 2010 Share Posted April 27, 2010 Is there a reason in wrapping $str in quotes? Link to comment https://forums.phpfreaks.com/topic/199950-capturing-first-6-characters-in-a-string/#findComment-1049515 Share on other sites More sharing options...
teamatomic Posted April 27, 2010 Share Posted April 27, 2010 Habit. As examples, I prefer: "this is a $var to echo out" over 'this is a'.$var.'to echo out' and file("$file") over file($file) HTH Teamatomic Link to comment https://forums.phpfreaks.com/topic/199950-capturing-first-6-characters-in-a-string/#findComment-1049574 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.