bobleny Posted March 2, 2009 Share Posted March 2, 2009 Hi, I have a quick little baby question. I'm simply having difficulties searching for the answer. I want to look at each character of a string. This will work: $var = "Joe"; echo strlen($var) ."<br />"; for($i = 0; $i < strlen($var); $i++) { echo $i. $var[$i] ."<br />"; } It will print: 3 0J 1o 2e ---------- That is, believe it or not, exactly what I want to do. However, I don't think that is the proper way of doing it. Is there not a pre-built function designed to return a character of a string at index $i? It has been my experience, that the way I am doing it above will either malfunction or will simply not work / won't compile. Thanks for you help! Link to comment https://forums.phpfreaks.com/topic/147526-how-do-i-return-a-character-of-a-string-at-index-i/ Share on other sites More sharing options...
trq Posted March 2, 2009 Share Posted March 2, 2009 Is there not a pre-built function designed to return a character of a string at index $i? substr. Link to comment https://forums.phpfreaks.com/topic/147526-how-do-i-return-a-character-of-a-string-at-index-i/#findComment-774446 Share on other sites More sharing options...
thebadbad Posted March 2, 2009 Share Posted March 2, 2009 But it's perfectly legal to access characters of a string with $str[index]. Link to comment https://forums.phpfreaks.com/topic/147526-how-do-i-return-a-character-of-a-string-at-index-i/#findComment-774450 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.