Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


What is difference between str_replace and substr_replace



What is difference between str_replace and substr_replace..

Answer / shivvshann

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

Post New Answer

More PHP Interview Questions

How to update memcached when you make changes to php?

0 Answers  


Which function will suitably replace 'x' if the size of a file needs to be checked? $Size=x(filename);

0 Answers  


What is scope of variable in php?

0 Answers  


What is return in php function?

0 Answers  


If the variable $var1 is set to 10 and the $var2 is set to the character var1, what's the value of $$var2?

0 Answers  


What is the difference between $message and $$message ?

7 Answers   Oracle, TouchStone,


What are the uses of explode() and implode() functions?

0 Answers  


What does $this do in php?

0 Answers  


How does api connect to database?

0 Answers  


How can you send http header to the client in php?

0 Answers  


How break and continue while loop in php?

0 Answers  


What are php loops?

0 Answers  


Categories