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? Quote Link to comment Share on other sites More sharing options...
Orio Posted March 13, 2007 Share Posted March 13, 2007 Use str_split($var1, 3)... You could make a function to do what you want, but it's much simpler to use str_split()... Orio. Quote Link to comment Share on other sites More sharing options...
Patrick3002 Posted March 13, 2007 Author Share Posted March 13, 2007 But what if i wanted to choose which chars to display like... if i wanted one var to be 'abc', one to be 'dac', or one to be 'hijb'? Quote Link to comment Share on other sites More sharing options...
Orio Posted March 13, 2007 Share Posted March 13, 2007 I can't really see a pattern here... Define exactly what the function you are looking for should make. Anyway, if you know what letters you want to display (IE- you dont need to display them by position or something), just output them directly... Orio. Quote Link to comment Share on other sites More sharing options...
Patrick3002 Posted March 13, 2007 Author Share Posted March 13, 2007 I want to take a string i.e: $var1="abcdefghijklmnopqrstuvwxyz"; and create a function to where i can select w/e i want from that variable wether it be 'kl' or 'def' or w/e. hopefully you understand its kinda weird Quote Link to comment Share on other sites More sharing options...
Orio Posted March 13, 2007 Share Posted March 13, 2007 So if you want a variable that has kl in it, create $kl = "kl"... I just don't understand your point. Orio. Quote Link to comment Share on other sites More sharing options...
Patrick3002 Posted March 13, 2007 Author Share Posted March 13, 2007 I want to be able to grab any part of a string and put it in another string so if i had: $image="custom/images/logo2.jpg"; i want to now echo image but i only want to echo /images/logo2.jpg i want to echo everything but custom Quote Link to comment Share on other sites More sharing options...
Orio Posted March 13, 2007 Share Posted March 13, 2007 <?php echo substr($image, strlen("custom")); ?> Orio. Quote Link to comment Share on other sites More sharing options...
Patrick3002 Posted March 13, 2007 Author Share Posted March 13, 2007 Ok, kewl. Is there some kind of array function that looks like this: $image[2]; That'll display the second array or something? Quote Link to comment Share on other sites More sharing options...
Patrick3002 Posted March 13, 2007 Author Share Posted March 13, 2007 Something like this.... $numbers = array("1","2","3","4","5"); echo $numbers[0]; (outputs 1) echo $numbers[1]; (outputs 2) etc... But instead i can use strings in the array func... is that right?? so like this: array("$var1","$var2","$var3"); can i use vars in an array func?? Quote Link to comment Share on other sites More sharing options...
Orio Posted March 13, 2007 Share Posted March 13, 2007 The script in your second post will work, but I haven't understood you question. Orio. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.