What is difference between str_replace and substr_replace
Difference between str_replace and substr_replace
str_replace —
Replace all occurrences of the search string with the
replacement string.
Example for str_replace()
<?php
echo str_replace("world","siva","Hello world!");
?>
substr_replace -
The function substr_replace introduces some additional
functionality to compliment str_replace. substr_replace is a
more mathematically based replace function, which relies on
starting points and lengths to replace parts of strings, as
opposed to searching and replacing.
Example for substr_replace()
//string that needs to be customized
$original = "ABC123 Hello Mr. siva! DEF321";
//starting point 5
$sp5 = substr_replace($original, "Five", 5);
//starting point 12
$sp12 = substr_replace($original, "Twelve", 12);
//starting point 0
$sp0 = substr_replace($original, "Zero", 0);
//starting point -1
$spneg1 = substr_replace($original, "Negative 1", -1);
//Echo each string
echo "Original String: $original <br />";
echo "Starting Point 5: $sp5 <br />";
echo "Starting Point 12: $sp12 <br />";
echo "Starting Point 0: $sp0 <br />";
echo "Starting Point -1: $spneg1 ";
| Is This Answer Correct ? | 2 Yes | 0 No |
Which variable declarations within a class is invalid in php?
Starting or restarting a computer is called
How can we do user authentication without using session/cookies ? For ex:- From page1 accepts user name and password and need to check in all other pages whether the user has logged in or not
What is mysql_real_escape_string used for?
Explain how is it possible to set an infinite execution time for php script?
what is the maximum size of databasi in mysql?
Explain the difference between require() and require_once()?
how to detect a mobile device using php
What is php how it works?
What is php limit?
Is php a float?
What is call by reference in php?