TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 12-29-2007, 03:04 AM   #1 (permalink)
The Visitor
Newcomer 
 
Join Date: Dec 2007
Posts: 3
Thanks: 0
exorcist is on a distinguished road
Default smiley code - clickable only with IE

Can anybody help me to fix that problem, because smileys are clickable ony with Internet Explorer, with Firefox they only work if you manualy write them in message body.

Code:
$message = str_replace ("\n","<br>", $message);
$message = str_replace ("|~~|","", $message);
$message = str_replace (":)","<img src=images/smile.gif>", $message);
$message = str_replace (":(","<img src=images/sad.gif>", $message);
$message = str_replace (":P","<img src=images/tongue.gif>", $message);
$message = str_replace (":o","<img src=images/scared.gif>", $message);
$message = str_replace (":C","<img src=images/mad.gif>", $message);
$message = str_replace (";)","<img src=images/rolleyes.gif>", $message);
$message = str_replace (";Y","<img src=images/thumbsup.gif>", $message);
$message = str_replace (":D","<img src=images/laugh.gif>", $message);
$message = str_replace (":s","<img src=images/shocking.gif>", $message);
$message = str_replace (":r","<img src=images/naughty.gif>", $message);
$message = str_replace (":-o","<img src=images/sweatdrop.gif>", $message);
$message = str_replace (":O)","<img src=images/clown.gif>", $message);
$message = str_replace (":H)","<img src=images/heart.gif>", $message);
$message = str_replace (":i)","<img src=images/info.gif>", $message);
$message = str_replace (":Q)","<img src=images/question.gif>", $message);
$message = stripslashes ($message);
exorcist is offline  
Reply With Quote
Old 12-29-2007, 04:36 AM   #2 (permalink)
The Wanderer
 
deflated's Avatar
 
Join Date: Dec 2007
Location: 127.0.0.1
Posts: 19
Thanks: 7
deflated is on a distinguished road
Default

Hello,

what do you mean by making an image clickable? Like a simple a-href link? I think your problem isn't a PHP specific issue. Anyway, I'd like to help you. Concerning your code: There are some things I'd do a bit different. For instance it would be faster to have to arrays $search and $replace that you pass to str_replace() instead of calling str_replace() for every smiley you replace by the filename. Here's the modified code. I hope there aren't any mistakes as I haven't tested it:

PHP Code:
$icons = array (
  
':)' => 'smile',
  
':(' => 'sad'
  
//...
);

//-----------------------------------------------

$search  = array();
$replace = array();

foreach (
$icons as $icon => $file) {
  
$search [] = $icon;
  
$replace[] = '<img src="http://www.talkphp.com/images/"' $icon '.gif">';
  
//if you want to have the icon clickable you need to use <a href="...">...</a>
}

$search  += array("\n"'|~~|');

//Andrew had the idea of using nl2br() Thanks!
//$replace += array('<br />', '');
$message nl2br($message);

$message str_replace($search$replace$message);

//are you using magic quotes or why do you want to strip out slashes from your message?
$message stripslashes($message); 

Last edited by deflated : 07-18-2010 at 01:47 PM.
deflated is offline  
Reply With Quote
Old 12-29-2007, 05:01 AM   #3 (permalink)
The Acquainted
 
Join Date: Sep 2007
Location: Arizona
Posts: 114
Thanks: 10
Andrew is on a distinguished road
Default

Also, for future reference, instead of using str_replace() to get new lines to <br>, you can use nl2br(). PHP: nl2br - Manual
Send a message via AIM to Andrew Send a message via MSN to Andrew
Andrew is offline  
Reply With Quote
The Following User Says Thank You to Andrew For This Useful Post:
deflated (12-29-2007)
Old 12-29-2007, 05:06 AM   #4 (permalink)
The Wanderer
 
deflated's Avatar
 
Join Date: Dec 2007
Location: 127.0.0.1
Posts: 19
Thanks: 7
deflated is on a distinguished road
Default

Good idea!
I've changed that in my code.
deflated is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 08:32 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design