helraizer 1 Light Poster

Hi folks,

I have an image based shoutbox which I am currently implementing emoticons onto. I have a way now for the emoticons to appear where the :D or =) etc. is on the image, but for some reason they seem to be conflicting. I shall try to explain.


chatbox.php - only necessary code shown

<?php
$grins = array('=D', "=d", ":d", ":D");
        foreach ($grins as $grin) {
            if (preg_match("/$grin/i", $text)) {
                $_SESSION['grin'] = $grin;
            }
        }
        $smiles = array("=)", ":)");
        foreach ($smiles as $smile) {
            if (preg_match("/$smile/i", $text)) {
                $_SESSION['smile'] = $smile;
            }
        }
?>

- that works, just showing you how the sessions are created.

Showimage_a.php - only necessary code shown

<?php

$grin_im = imagecreatefromgif("icon_grin.gif"); //grinning emote
$blark = ImageColorAllocate($grin_im, 0, 0, 0);

$smile_im = imagecreatefromgif("icon_smile.gif"); // smiley emote
$blacks = imagecolorallocate($smile_im, 0, 0, 0);

$image = ImageCreateFromGIF("660x240background2.gif"); //main shoutbox image
$blue = ImageColorAllocate($image, 200, 200, 255); // prepare some blueness
$black = ImageColorAllocate($image, 0, 0, 0); // ... and whiteness

$cur_line_y = 60; // This stores how far down the image the current line will print
$cur_line_x = 24; // This stores how far across the image the current line will print
$pagecharwidth = 75; // this is the maximum length of the line before it wraps;
$lineheight = 18; // This is how much to move down to print the next line
$pagelinelimit = 1; // This is the maximum number lines of text that can be displayed

for ($i = 0; $i < $numberOfLines; $i++) {
    while ($row = mysql_fetch_array($result)) {

//code for putting shouts onto image is here - irrelevant for this purpose

$cur_line_y += $lineheight;

        if (isset($_SESSION['grin'])) {

            $grin = $_SESSION['grin'];
            $pos = strpos($line, $grin);

            if ($font == "palab") {
                $post = $pos * 5.6;
            } elseif ($font == "comicsans") {
                $post = $pos * 6.7;
            } else {
            }

            if (preg_match("/$grin/i", $line)) {


                imagecopymerge($image, $grin_im, ($cur_line_x + $post), ($cur_line_y - 30), 0, 0,
                    15, 15, 100);

            }

        }

 if (isset($_SESSION['smile'])) { // from here

            $smiles = $_SESSION['smile'];
            $smile_pos = strpos($line, $smiles);

            if ($font == "palab") {
                $posts = $smile_pos * 5.6;
            } elseif ($font == "comicsans") { // not mono-spaced fonts
                $posts = $smile_pos * 6.7;
            } else {
            }


            if (preg_match("/$smiles/i", $line)) {

                imagecopymerge($image, $smile_im, ($cur_line_x + $posts), ($cur_line_y - 30), 0,
                    0, 15, 15, 100);
            }
        } // to here

    } //end while 


} // end for
?>

So what it's supposed to do is if ':D' '=D' ':d' '=d' (emoticon string) are present in the string then it adds the image 'icon_grin.gif' to the main image over where that emoticon string is found. It should also add 'icon_smile.gif' to the main image where :) or =) is found in the string. The thing is that if I comment out the bits inbetween 'from here' and 'to here' in that code, then the icon_grin is added to where :D =D :d or =d is found but if I uncomment it then icon_smile is added to where :D =D :d or =d are, instead of :) =).

Can you see where the problem is arising? I have given all relevant code and can't see why they are conflicting like that..

Thanks,
Sam

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.