Re: Another new PHP programmer question...

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Jan 3, 2008 3:56 AM, Ben Stones <bastones@xxxxxxxxxxxxxx> 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.

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux