Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.