String Manipulation in PHP
-
Upload
suraj-motee -
Category
Technology
-
view
126 -
download
1
Transcript of String Manipulation in PHP
PHP-Strings
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?
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.
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
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