Tags
Asked 2 years ago
9 Jun 2021
Views 203
dilip

dilip posted

how to use str_replace in php ?

how to use str_replace in php ?
jaman

jaman
answered Aug 17 '21 00:00


$newstring=str_replace(".csv","",'stock.csv');
echo $newstring;

output : stock
above code replace .csv from the stock.csv and return stock only

str_replace() is function in PHP used for the replace the matching portion of the string to another string , from given string
str_replace(string to find,replace part,main string)
so suppose "hello world" is main string , if you want to replace the "world" string with string "global" then
str_replace("hello","global","Hello world")

hanuman

hanuman
answered Feb 22 '22 00:00


str_replace() is a function for replacing text with some other text so you can use it to change some text in php.


Replace the characters "Hello" in the string "Hello Arrayoverflow!" with "Hi":


<?php
echo str_replace("Hello","Hi","Hello Arrayoverflow!");
?>



Post Answer