HoTDaWg Posted January 31, 2009 Share Posted January 31, 2009 lmfao im fresh outta turing so forgive me lol here is a basic string manipulation application assigning a letter from a string onto an array: <?php $stringofletters = "abcdefghijklmnopqrstuvwxyz"; $letters = array(); for ($i = 1; $i <= strlen($stringofletters); $i ++) { $letters($i) = $stringofletters($i); #This is where the problem is } ?> im having trouble with pointing to a specific character in the stringofletters. here is the error im getting: Fatal error: Can't use function return value in write context in C:\xampp\htdocs\learnphp\hacks\test.php on line 6 how do i go about referring to a specific character in the string? Quote Link to comment https://forums.phpfreaks.com/topic/143211-solved-basic-string-manipulation/ Share on other sites More sharing options...
landavia Posted January 31, 2009 Share Posted January 31, 2009 <?php $stringofletters = "abcdefghijklmnopqrstuvwxyz"; $letters = array(); for ($i = 1; $i <= strlen($stringofletters); $i ++) { $letters[$i] = $stringofletters[$i]; #This is where the problem is } ?> do you happen VB programer before done PHP? Quote Link to comment https://forums.phpfreaks.com/topic/143211-solved-basic-string-manipulation/#findComment-751072 Share on other sites More sharing options...
premiso Posted January 31, 2009 Share Posted January 31, 2009 You are using () instead of [] for accessing an array. Quote Link to comment https://forums.phpfreaks.com/topic/143211-solved-basic-string-manipulation/#findComment-751073 Share on other sites More sharing options...
HoTDaWg Posted January 31, 2009 Author Share Posted January 31, 2009 oh hahah thanks thank you its a force of habit from turing:P i guess vb might have the syntax i wouldnt know. but now im getting this error: Fatal error: Call to undefined function abcdefghijklmnopqrstuvwxyz() in C:\xampp\htdocs\learnphp\hacks\test.php on line 6 im guessing this has to do with my inital question here is the updated code <?php $stringofletters = "abcdefghijklmnopqrstuvwxyz"; $letters = array(); for ($i = 1; $i <= strlen($stringofletters); $i ++) { $letters[$i] = $stringofletters($i); } ?> how do i refer to a specific character in that string? thanks Quote Link to comment https://forums.phpfreaks.com/topic/143211-solved-basic-string-manipulation/#findComment-751076 Share on other sites More sharing options...
.josh Posted January 31, 2009 Share Posted January 31, 2009 actually, you need to be using { } $stringofletters = "abcdefghijklmnopqrstuvwxyz"; echo $stringofletters{4}; // output: e but looking at your code, if you have php5+ you can just use str_split to accomplish the same thing. Quote Link to comment https://forums.phpfreaks.com/topic/143211-solved-basic-string-manipulation/#findComment-751079 Share on other sites More sharing options...
HoTDaWg Posted January 31, 2009 Author Share Posted January 31, 2009 excellent thanks very much! Quote Link to comment https://forums.phpfreaks.com/topic/143211-solved-basic-string-manipulation/#findComment-751080 Share on other sites More sharing options...
.josh Posted January 31, 2009 Share Posted January 31, 2009 also, if you don't have php5+ you can use range instead: $letters = range('a','z'); Quote Link to comment https://forums.phpfreaks.com/topic/143211-solved-basic-string-manipulation/#findComment-751082 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.