Re: Another new PHP programmer question...
| From: | Daniel Brown | Date: | Fri, 04 Jan 2008 16:12:17 +0000 |
| Subject: | Re: Another new PHP programmer question... | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-44483@lists.php.net to get a copy of this message | ||
On Jan 3, 2008 3:56 AM, Ben Stones <bastones@googlemail.com> wrote:
> Hello,
>
> Thank you for your help previously everyone, I was able to fix that problem.
> The thing now, is that I want to add smileys to the messages; i.e. :) would
> equal to a smiley image when posting a message.
Where you want that, add this:
<?
$smile = array(':-)' => 'smile',
':)' => 'smile',
';-)' => 'wink',
';)' => 'wink',
':-P' => 'tongue',
':P' => 'tongue');
foreach($smile as $p => $v) {
// The following is done to allow the regexp to function normally.
$p = str_replace(')','\)',str_replace('(','\(',$p));
$post = preg_replace('/'.$p.'/U','<img
src="/graphics/smileys/'.$v.'.gif" />',$post);
}
?>
This assumes that you have smiley images in /graphics/smileys/ and
that they're .gif images named as shown in the second part of each
array item.
Also, keep in mind that, before you insert ANY user-posted data
into your database, you should escape it. For example:
$post = mysql_real_escape_string($post);
--
Daniel P. Brown
[Phone Numbers Go Here!]
[They're Hidden From View!]
If at first you don't succeed, stick to what you know best so that you
can make enough money to pay someone else to do it for you.