php - Adjusting BBcode parser to note parse smileys in URLs?

Solution:
You can use preg_replace() instead ofstr_replace()
and check if smiley is bounded by a space (or start of string, or end of string)
Code:
$smilies = array(
"/( |^)><( |$)/" => ' <img src="/jscripts/sce/emoticons/angry.png" alt="" /> ',
"/( |^):'\(( |$)/" => ' <img src="/jscripts/sce/emoticons/cry.png" alt="" /> ',
"/( |^):S( |$)/" => ' <img src="/jscripts/sce/emoticons/dizzy.png" alt="" /> ',
"/( |^):D( |$)/" => ' <img src="/jscripts/sce/emoticons/grin.png" alt="" /> ',
"/( |^)\^_\^( |$)/" => ' <img src="/jscripts/sce/emoticons/happy.png" alt="" /> ',
"/( |^)<3( |$)/" => ' <img src="/jscripts/sce/emoticons/heart.png" alt="" /> ',
"/( |^):huh:( |$)/" => ' <img src="/jscripts/sce/emoticons/huh.png" alt="" /> ',
"/( |^):\|( |$)/" => ' <img src="/jscripts/sce/emoticons/pouty.png" alt="" /> ',
"/( |^):\(( |$)/" => ' <img src="/jscripts/sce/emoticons/sad.png" alt=""/> ',
"/( |^):O( |$)/" => ' <img src="/jscripts/sce/emoticons/shocked.png" alt="" /> ',
"/( |^):sick:( |$)/" => ' <img src="/jscripts/sce/emoticons/sick.png" alt="" /> ',
"/( |^):\)( |$)/" => ' <img src="/jscripts/sce/emoticons/smile.png" alt="" /> ',
"/( |^):P( |$)/" => ' <img src="/jscripts/sce/emoticons/tongue.png" alt="" /> ',
"/( |^):S( |$)/" => ' <img src="/jscripts/sce/emoticons/unsure.png" alt="" /> ',
"/( |^):woot:( |$)/" => ' <img src="/jscripts/sce/emoticons/w00t.png" alt="" /> ',
"/( |^):whistle:( |$)/" => ' <img src="/jscripts/sce/emoticons/whistle.png" alt="" /> ',
"/( |^);\)( |$)/" => ' <img src="/jscripts/sce/emoticons/wink.png" alt="" /> ',
"/( |^):wub:( |$)/" => ' <img src="/jscripts/sce/emoticons/wub.png" alt="" /> '
);
$body=preg_replace( array_keys($smilies), array_values($smilies), $body );
See it in action here.
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: deprecated: directive 'allow_url_include' is deprecated in unknown on line 0
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.