I am trying to analyse the text then when I saw ":)" I will replace it with the path of the image is there a way to make that happened?
Thanks in advance..
$text = "This would be fun :)"
wanted result = "This would be fun image path here"
so instead of ":)" I will see the path of the image to appear smiley
$text = "This would be fun :)"
$newtext = str_replace(":)", "<img src='images/smiley.png'>", $text);
for multiple replace find example below from php.net
$vowels = array("a", "e", "i", "o", "u", "A", "E", "I", "O", "U");
$onlyconsonants = str_replace($vowels, "", "Hello World of PHP");
// Provides Result: Hll Wrld f PHP
Thanks kamlesh
as I read about str_replace I derived to this solution
$str = "It would be fun :)";
$image_path_smile = "<img class='emoticons' src='images/smile.png'/>";
$pattern=array();
$pattern[0]=":)";
$replacement=array();
$replacement[0]=$image_path_smile;
str_replace($pattern,$replacement,$str);
Thanks for the quick response :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With