suttercain Posted March 12, 2007 Share Posted March 12, 2007 Hi Everyone, I am doing a lab exercise and here is the code: <?php print "<b>Here is the original string:</b>"; $string = " mary jones lives in santa cruz, california at 22 ocean drive."; /********************************************************************************************************************************* ***** a. Find the number of characters in the string. ***** b. Capitalize all the letters in the string. ***** c. Now Make all the Characters lowercase. ***** d. Use the substr() function to print Santa Cruz, California. The first letter in each word will be in uppercase. ***** e. Use the substr() function to print Mary's street address. ***** f. Trim out the whitespace at the begginning of the string. ***** g. Find the index position of California. ***** h. Replace Santa Cruz with Los Altos (case insensitive. ***** i. Find the number of words in the string. *********************************************************************************************************************************/ print $string . "<p>"; $a = strlen($string); print "a. This string is $a characters long." . "<br>"; $b = strtoupper($string); print "b. $b" . "<br>"; $c = strtolower($string); print "c. $c" . "<br>"; $d = ucwords(substr ($string, 23, 22)); print "d. $d" . "<br>"; $e = substr($string, -15, 16); print "e. $e" . "<br>"; $f = substr($string, -15, 16); print "f. $f" . "<br>"; $g = substr($string, -15, 16); print "g. $g" . "<br>"; $h = str_replace("santa cruz", "Los Altos", $string); print "h. $h" . "<br>"; $i = str_word_count($string); print "i. $i" . "<br>"; ?> I need help for letter "g" which is "Find the index position of California." Can anyone assist? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/42292-solved-find-the-index-position-in-a-string/ Share on other sites More sharing options...
brad Posted March 12, 2007 Share Posted March 12, 2007 i think you need to use a combination of strstr(); and strpos(); but i am wayy too tired to load another blank document to have a bash Quote Link to comment https://forums.phpfreaks.com/topic/42292-solved-find-the-index-position-in-a-string/#findComment-205164 Share on other sites More sharing options...
suttercain Posted March 12, 2007 Author Share Posted March 12, 2007 I tried: $string = " mary jones lives in santa cruz, california at 22 ocean drive."; $g = strpos($string, 'California'); print "g. $g" . "<br>"; But the output was blank for line "g" Quote Link to comment https://forums.phpfreaks.com/topic/42292-solved-find-the-index-position-in-a-string/#findComment-205168 Share on other sites More sharing options...
suttercain Posted March 12, 2007 Author Share Posted March 12, 2007 It was case sensitive. Quote Link to comment https://forums.phpfreaks.com/topic/42292-solved-find-the-index-position-in-a-string/#findComment-205170 Share on other sites More sharing options...
brad Posted March 12, 2007 Share Posted March 12, 2007 sweet =] Quote Link to comment https://forums.phpfreaks.com/topic/42292-solved-find-the-index-position-in-a-string/#findComment-205173 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.