Purchase Solution

Php script to search for words in a string

Not what you're looking for?

Ask Custom Question

Write a PHP script named states.php that creates a variable $states with the value "Mississippi Alabama Texas Massachusetts Kansas". The script should perform the following tasks:

a) Search for a word in $states that ends in xas. Store this word in element 0 of an array named $statesArray.
b) Search for a word in $states that begins with k and ends in s. Perform a case-insensitive comparison. Store this word in element 1 of $statesArray.
c) Search for a word in $states that begins with M and ends in s. Store this element in element 2 of the array.
d) Search for a word in $states that ends in a. Store this word in element 3 of the array.
e) Search for a word in $states at the beginning of the string that starts with M. Store this word in element 4 of the array.
f) Output the array $statesArray to the screen.

Purchase this Solution

Solution Summary

This solution assumes that you have basic familiarity with regular expressions.

Solution Preview

Please rename the attached 380411-states.php as per your requirement.

Below is the output produced by the script.

$ php 380411-states.php
Array
(
[0] => Texas
[1] => Kansas
...

Purchase this Solution


Free BrainMass Quizzes
Inserting and deleting in a linked list

This quiz tests your understanding of how to insert and delete elements in a linked list. Understanding of the use of linked lists, and the related performance aspects, is an important fundamental skill of computer science data structures.

Javscript Basics

Quiz on basics of javascript programming language.

Basic Computer Terms

We use many basic terms like bit, pixel in our usual conversations about computers. Are we aware of what these mean? This little quiz is an attempt towards discovering that.

C++ Operators

This quiz tests a student's knowledge about C++ operators.

Word 2010: Tables

Have you never worked with Tables in Word 2010? Maybe it has been a while since you have used a Table in Word and you need to brush up on your skills. Several keywords and popular options are discussed as you go through this quiz.