Board index   FAQ   Search  
Register  Login
Board index PHP PHP General

some problems with a script

General discussions related to php

Moderators: macek, egami, gesf

some problems with a script

Postby z3phir » Wed Jun 25, 2003 1:50 pm

I found a class on the net and it has some errors on it.

here's the class

<?php

class Smileys {
var $_smileys = array();
var $error_message = '';
function smileys($url) {
$this->_resetSmileys($url);
}

function insertSmileys($str) {
// for each smileys
for ($i=0; $i < sizeof($this->_smileys); $i++) {
$smiley = $this->_smileys[$i][0];
$image = $this->_smileys[$i][1];
$x = $this->_smileys[$i][2];
$y = $this->_smileys[$i][3];
$replace = "<img src=\"$image\" alt=\"$smiley\" width=\"$x\" height=\"$y\" border=\"0\">";
// replace it with the image tag
$str = str_replace($smiley, $replace, $str);
}
return $str;
}

function getSmileys() {
return $this->_smileys;
}

function _resetSmileys($url) {
// erase old list
$this->_smileys = array();
// open smileys definition
$fp = @fopen($url, "r");
// does the file exist?
if (@$fp) {
while (!feof ($fp)) {
// read one line
$buffer = fgets($fp,4096);
// is it not a comment or emtpy
if ((strpos($buffer, "##") == false) && (ord($buffer) > 31)) {
$buffer = str_replace("\n", "", $buffer);
// get the definition
$list = explode("\t", $buffer);
// get the size
$size = @GetImageSize($list[1]);
// is it an image?
if ($size != false) {
$list[2] = $size[0];
$list[3] = $size[1];
// add the definition to the smileys array
array_push($this->_smileys, $list);
print"<img src='$list[1]' alt='$list[0]' $size[3] border='0'>";
}
}
}
fclose ($fp);
} else {
$this->error_message .= "resetsmileys(): Error opening file!\n";
return -1;
}
}
}
?>

this is the test file <?php
require "Smileys.php";

$class = new Smileys("smileys.txt");
$smileys = $class->getSmileys();
echo $class->insertSmileys(":trooper::tr:<p>\n");
?>

and here is the text file i use
:trooper: smileys/19.gif
:tr: smileys/08.gif

the clas it works but only if there is a line of text not more
can anyone help ?
z3phir
New php-forum User
New php-forum User
 
Posts: 2
Joined: Wed Jun 25, 2003 1:42 pm

Postby Redcircle » Wed Jun 25, 2003 5:45 pm

the clas it works but only if there is a line of text not more
can anyone help ?


It only works for one line? I'm not following what you mean by that. One line of what?
User avatar
Redcircle
Moderator
Moderator
 
Posts: 830
Joined: Tue Jan 21, 2003 10:42 pm
Location: Michigan USA

one line in the txt

Postby z3phir » Wed Jun 25, 2003 6:43 pm

" and here is the text file i use
:trooper: smileys/19.gif
:tr: smileys/08.gif "

the class only works for the last line of in the txt file :tr: smileys/08.gif
z3phir
New php-forum User
New php-forum User
 
Posts: 2
Joined: Wed Jun 25, 2003 1:42 pm


Return to PHP General

Who is online

Users browsing this forum: Google [Bot] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron