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"); while($row = mysqli_fetch_array($Fruits)) { $content = str_replace($row['word'], $row['replace'], $content); } return $content; } $string = 'An apple better then sugar, but orange not'; echo replaceString($mysqli, $string);
Show:  
Copy Clear