php-mysqlHow to replace a string in MySQL using PHP?
Replacing a string in MySQL using PHP can be done using the str_replace()
function.
$string = "This is a string";
$new_string = str_replace("string", "sentence", $string);
echo $new_string;
Output example
This is a sentence
The str_replace()
function takes three parameters:
- The string to be replaced
- The string to replace it with
- The string to search in
The function will then search for the first parameter in the third parameter and replace it with the second parameter.
Helpful links
More of Php Mysql
- How to output XML from MySQL using PHP?
- How to get the last insert ID in PHP MySQL?
- How to update to null value in MySQL using PHP?
- How to get a single value from query in PHP MySQL?
- How to get the version of MySQL using PHP?
- How to use utf8mb4_unicode_ci in MySQL with PHP?
- How to store a BLOB in a MySQL database using PHP?
- How to keep a connection open in PHP and MySQL?
- How to use a MySQL union in PHP?
- How to escape a string for MySQL in PHP?
See more codes...