I have test code
$chatText = "Hello world :D";
$chatText = str_replace(":D","<img src='happy.jpg' width='20' height='20' alt='Big Smile' />",$chatText);
echo $chatText;
basically what it does is replace the :D
with an image
.
What I actually wanted to do is after clicking submit from a <textarea>
-replace input value i.e emoticons (image) after post.
How do I check user's input value to check to see if they have type these characters for example
":-)"
No need to check as str_replace will replace everything it matches, only check if the post isn't empty.
<?php
if($_POST['textarea_name']!=""){
$text = $_POST['textarea_name'];
$chatText = str_replace(":D","<img src='happy.jpg' width='20' height='20' alt='Big Smile' />",$text);
echo $chatText;
}
?>
Check this out for more detailed replacement using arrays;