To replace a character(s) in a string in PHP, you can use the str_replace()
function.
The syntax for the str_replace()
function is as follows:
main.php42 chars2 lines
Here, $search
is the character(s) that you want to replace, $replace
is the new character(s) with which you want to replace the old character(s), and $subject
is the string that you want to modify.
Here's an example:
main.php91 chars4 lines
In this example, we're replacing the comma ,
in the original string with a pipe |
. The output of this code will be:
main.php14 chars2 lines
As you can see, the comma has been replaced with a pipe in the new string.
gistlibby LogSnag