The principle of operation of my code is as follows: if there are such lowercase emoticons (":)", ":(") in the entered line, then you need to replace them with pictures. Here is how I do it:
$smile = array(":)", ":("); $grafic = array("<img src = './image/Smile.png' alt='Smile' align='middle'>", "<img src = './image/Sad.png' alt='Smile' align='middle'>"); $new_message = str_replace($smile, $grafic, $message); $file = "../data/messages.json"; $json_content = json_decode(file_get_contents($file), true); if (!empty($new_message)) { $json_content[] = array("time" => $time, "user" => $user, "message" => $new_message); file_put_contents($file, json_encode($json_content, JSON_PRETTY_PRINT)); } But then, the already changed line I need to write to the "base" ( json file) turns out the following:
[ { "time": "1499985376", "user": "Max", "message": "Hello <img src = '.\/image\/Smile.png' alt='Smile' align='middle'>" } ] How can I make it so that, for example, the word "Smile" or "Sad" is written instead of HTML code?
:)on a piece of HTML, then it will be difficult to change the picture. Therefore, I support the point of view of @Visman - convert only after withdrawal from the database. - Nick Volynkin ♦