Jump to content

[SOLVED] Find the index position in a string...


suttercain

Recommended Posts

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.