helraizer Posted May 31, 2008 Share Posted May 31, 2008 Hey folks and folksesses, I have written some code to get emoticons onto my image based shoutbox but there is quite a large bug, as there is with any code in the early stages, and I need your help to narrow it down for me. The idea is that the script pulls data from the database - username, colour, font and shout to print '[username] shout' onto the image. This part of the code all works perfectly. Then it looks through each line at a time to see if there is either , , or in the shout, if there is it finds the position of the string it's at, uses this data * a number to get the emote to the correct place on the image. After it has found that result and merged the emoticon onto the shoutbox, it deletes the , , or from that shout, depending on which was used from the shout so that there is no overlapping of text and image. This works fine for the - the test post "Yay!! " gives this result (top line) Whereas the post "Yay!! " gives the result ^ it deletes the entire username and shout from the image and merges the emoticon into place. showimage_a.php <?php $name = "[" . htmlspecialchars_decode($row['username']) . "] "; //it works - returns username $font = $row['font']; //it works - renders the colour $color = $row['color']; //it works - changes the font $line = htmlspecialchars_decode($row['comment']); //it works, posts the shout if ($name == "[] ") { $name = ""; $line = $name . $line; } else { $line = $name . $line; } if (isset($_SESSION['sad'])) // not entirely implemented, does not register a session yet { $sad = $_SESSION['sad']; $sad_pos = strpos($line, $sad); if ($font == "palab") { $postb = $sad_pos * 5.4; } elseif ($font == "comicsans") { $postb = $sad_pos * 6.725; } else { } if (stristr($line, $sad)) { imagecopymerge($image, $sad_im, ($cur_line_x + $postb), (($cur_line_y + $lineheight) - 30), 0, 0, 15, 15, 100); $line = preg_replace('/:(/', "", $line); } } if (isset($_SESSION['smiley'])) { $smiley = $_SESSION['smiley']; $smile_pos = strpos($line, ""); if ($font == "palab") { $posts = $smile_pos * 5.36; } elseif ($font == "comicsans") { $posts = $smile_pos * 6.725; } else { } if (stristr($line, $smiley)) { imagecopymerge($image, $smile_im, ($cur_line_x + $posts), (($cur_line_y + $lineheight) - 30), 0, 0, 15, 15, 100); $line = preg_replace('', "", $line); //doesn't render on some occassions due to sessions - not causing this problem. } } if (isset($_SESSION['tongue'])) { $tongue = $_SESSION['tongue']; $ton_pos = strpos($line, $tongue); if ($font == "palab") { $postt = $ton_pos * 5.1; } elseif ($font == "comicsans") { $postt = $ton_pos * 6.725; } else { } if (stristr($line, $tongue)) { imagecopymerge($image, $tongue_im, ($cur_line_x + $postt), (($cur_line_y + $lineheight) - 30), 0, 0, 15, 15, 100); $line = preg_replace('/:P/', "", $line); //For some reason removes the entire $line and adds $smile_im to the image. *confused* } } if (isset($_SESSION['grin'])) { $grin = $_SESSION['grin']; $pos = strpos($line, $grin); if ($font == "palab") { $post = $pos * 5.7; } elseif ($font == "comicsans") { $post = $pos * 6.725; } else { } if (stristr($line, $grin)) { imagecopymerge($image, $grin_im, ($cur_line_x + $post), (($cur_line_y + $lineheight)- 30.5), 0, 0, 15, 15, 100); $line = preg_replace('/:D/', "", $line); // This bit works fine (gives the first result from Yay!! } } if ($color == "white" || $color == "yellow" || $color == "green" || $color == "orange" || $color == "aqua") { Imagettftext($image, 10, 0, $cur_line_x, $cur_line_y, getColor($color), getfont ($font), trim($line)); } elseif ($color != "white" || $color != "yellow" || $color != "green" || $color != "orange" || $color != "aqua") { Imagettftext($image, 10, 0, $cur_line_x, $cur_line_y, $white, getfont($font), trim($line)); } elseif ($font == "fixedsys" || $font == "Courbd" || $font == "arial" || $font == "timesnr" || $font == "calibri" || $font == "comicsans" || $font == "palab") { Imagettftext($image, 10, 0, $cur_line_x, $cur_line_y, getColor($color), getfont ($font), trim($line)); } else { Imagettftext($image, 10, 0, $cur_line_x, $cur_line_y, $white, "courbd.ttf", trim ($line)); } ?> Any ideas? Please reply, Sam Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted May 31, 2008 Share Posted May 31, 2008 try using backslashes like in your yay code $line = preg_replace('/:)/', "", $line); Quote Link to comment Share on other sites More sharing options...
helraizer Posted May 31, 2008 Author Share Posted May 31, 2008 Wow, your first response was the charm.. I changed preg_replace to str_replace and now it works perfectly. xD It always seems to be the simplest answers. Thank you very much for that! Sam Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted May 31, 2008 Share Posted May 31, 2008 yupp i was going to suggest str_replace next anyhow solve topic please Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.