flappy_warbucks Posted March 13, 2007 Share Posted March 13, 2007 Hi, Is there any way to turn a string into an array (well obviously there is a way to do it, i just cant figure out how) i was thinking there must be a class in PHP what allows you to do that, either in a loop, or something built in. i.e. class_name("4", $mystring); its buggering me, so pwease help *puppy dog eyes* thankys Link to comment https://forums.phpfreaks.com/topic/42499-solved-turning-a-string-into-an-array/ Share on other sites More sharing options...
Orio Posted March 13, 2007 Share Posted March 13, 2007 In what way do you want to make it an array? Maybe you are looking for str_split()? (PHP5+) Orio. Link to comment https://forums.phpfreaks.com/topic/42499-solved-turning-a-string-into-an-array/#findComment-206177 Share on other sites More sharing options...
flappy_warbucks Posted March 13, 2007 Author Share Posted March 13, 2007 In what way do you want to make it an array? Maybe you are looking for str_split()? (PHP5+) Orio. YES YES YES THATS IT!!!! THANK YOU THANK YOU THANK YOU Link to comment https://forums.phpfreaks.com/topic/42499-solved-turning-a-string-into-an-array/#findComment-206178 Share on other sites More sharing options...
kenrbnsn Posted March 13, 2007 Share Posted March 13, 2007 You can treat a string as an array: <?php $var1="abcdefghij"; for($i=0;$i<strlen($var1);$i++) echo $var1[$i].'<br>'; ?> Ken Link to comment https://forums.phpfreaks.com/topic/42499-solved-turning-a-string-into-an-array/#findComment-206179 Share on other sites More sharing options...
flappy_warbucks Posted March 13, 2007 Author Share Posted March 13, 2007 You can treat a string as an array: <?php $var1="abcdefghij"; for($i=0;$i<strlen($var1);$i++) echo $var1[$i].'<br>'; ?> Ken Oooh i like that one too... Both good Link to comment https://forums.phpfreaks.com/topic/42499-solved-turning-a-string-into-an-array/#findComment-206183 Share on other sites More sharing options...
Patrick3002 Posted March 13, 2007 Share Posted March 13, 2007 <?php $var1="abcdefghij"; for($i=0;$i<strlen($var1);$i++) echo $var1[$i].'<br>'; ?> Using that code above... How would i select more than one letter at a time and put it into individual strings for example: If i used that code and wanted to be able to so this: echo $var1[abc]; ( outputs 'abc' ) echo $var1[def]; ( outputs 'def' ) echo $var1[ghij]; ( outputs 'ghij' ) How would i modify that script to do that? Link to comment https://forums.phpfreaks.com/topic/42499-solved-turning-a-string-into-an-array/#findComment-206188 Share on other sites More sharing options...
flappy_warbucks Posted March 13, 2007 Author Share Posted March 13, 2007 <?php $var1="abcdefghij"; for($i=0;$i<strlen($var1);$i++) echo $var1[$i].'<br>'; ?> Using that code above... How would i select more than one letter at a time and put it into individual strings for example: If i used that code and wanted to be able to so this: echo $var1[abc]; ( outputs 'abc' ) echo $var1[def]; ( outputs 'def' ) echo $var1[ghij]; ( outputs 'ghij' ) How would i modify that script to do that? what that code does is effectively give you an array from the string (which is what i wanted to do), if you wanted individual strings then i would reference that part of the array instead of making a batch of new strings. why make more work for yourself? Link to comment https://forums.phpfreaks.com/topic/42499-solved-turning-a-string-into-an-array/#findComment-206196 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.