PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
CREATE TABLE Fruits (id int, `word` varchar(64), `replace` varchar(64)); INSERT INTO Fruits VALUES (1, 'apple', 'banana'), (2, 'orange', 'pear');
Copy Clear
Copy Format Clear
<?php function replaceString ($mysqli, $content){ $fruits = $mysqli->query("SELECT * FROM Fruits ORDER BY id DESC"); $rows = $fruits->fetch_all(MYSQLI_ASSOC); return str_replace(array_column($rows, 'word'), array_column($rows, 'replace'), $content); } $string = 'An apple better then sugar, but orange not'; echo replaceString($mysqli, $string);
Show:  
Copy Clear