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? 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? 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. 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 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. 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! 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'); Link to comment https://forums.phpfreaks.com/topic/143211-solved-basic-string-manipulation/#findComment-751082 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.