2
How to replace a word inside a string in PHP
source link: https://www.laravelcode.com/post/how-to-replace-a-word-inside-a-string-in-php
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
How to replace a word inside a string in PHP
Use the PHP str_replace()
function
You can use the PHP str_replace()
function to replace all the occurrences of a word within a string.
In the following example, the word "facts" is replaced by the word "truth".
<?php
$my_str = 'If the facts do not fit the theory, change the facts.';
// Display replaced string
echo str_replace("facts", "truth", $my_str);
?>
I hope you like this small article.
Author : Harsukh Makwana
Hi, My name is Harsukh Makwana. i have been work with many programming language like php, python, javascript, node, react, anguler, etc.. since last 5 year. if you have any issue or want me hire then contact me on [email protected]
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK