String Manipulation in PHP

5
PHP-Strings

Transcript of String Manipulation in PHP

Page 1: String Manipulation in PHP

PHP-Strings

Page 2: String Manipulation in PHP

A string is a sequence of characters, like "Hello world!".

We will take a look at some extended examples on PHP Strings.

What are strings?

Page 3: String Manipulation in PHP

What is the length of the following string: “Suraj is cool”?

At what index does “u” start? Write a program to find the number of words in the line.

Reverse the string “Hello world!”.

Example 1: String Manipulation.

Page 4: String Manipulation in PHP

The PHP strpos() function searches for a specific text within a string.

If a match is found, the function returns the character position of the first match. If no match is found, it will return FALSE.

Strpos

Page 5: String Manipulation in PHP

The PHP str_replace() function replaces some characters with some other characters in a string.

Replace the “word” by “hello” in the following string.

“Test Word”

Replace text within a string