- Forums
- PHP
- Replace Parts Of A PHP String Replacing Words Characters
This Page Contains information about Replace Parts Of A PHP String Replacing Words Characters By wallpaperama in category PHP with 2 Replies. [1043], Last Updated: Sat May 18, 2024
wallpaperama
Wed Jun 20, 2007
2 Comments
4902 Visits
if you ever wanted to know how to change a character in a string, its easy with php.
lets say i have a string, the this is the value:
$string = "Wallpaperama has many screensavers you can download for free in our screensavers page"
ok, lets say i want to change all the words "screensavers" to "wallpapers" and this is how i would do it:
<?
$string = "Wallpaperama has many screensavers you can download for free in our screensavers page"
echo str_replace(('screensavers','wallpapers',$string);
?>
with this code, i am telling php that i want to replace any part of the string that contains "screensavers" and replace it with "wallpapaers" and the ouput will be like this
Wallpaperama has many wallpapers you can download for free in our wallpapers page
this is the format to use this function:
str_replace ('find this', 'replace it with this', 'in this')
this:
echo str_replace(('screensavers','wal
should be
str_replace('screensavers','
one less bracket before 'screensavers'.