View Single Post
Old 02-06-2008, 05:31 PM   #1 (permalink)
Nor
The Addict
 
Join Date: Nov 2007
Posts: 282
Thanks: 61
Nor is on a distinguished road
Default This stupid str_replace bug?

str_replace bug in PHP 5.2.4?

I got this function right:

Code:
function getEmoticons( $key, $post )
{
	global $mysqli;
	$query = $mysqli->query("SELECT * FROM `zbemoticons` WHERE `userkey` = '{$key}'");
	if( $query )
	{
		$q = array();
		while( $fetch = $query->fetch_array() )
		{
			$q[] = $fetch;
		}
		for($x=0;$x<count($q);$x++)
		{
			$image = '<' . 'img' . ' src='. '\'' . $q[$x]['image']. '\'' . '/' . '>';
			$text = $q[$x]['text'];
			$post = str_replace( $text, $image, $post );
			//$post = str_replace( trim($q[$x]['text']), trim($q[$x]['image']), $post );
		}
		return $post;
	}
	else
	{
		return $post;
	}
}
As you might notice you would simply think the image is parsed correctly?

This is the outcome:

Code:
shouts[n++] = "<a href='http://s1.zetaboards.com/uStore/profile/31283'>Nor</a> -- <span style='color: black'> <img src='http://<img src='http://norvisions.info/emoticons/evilgrin.gif'/>visions.info/emoticons/hehe.gif'/> </span> "
How come the stupid image is being replaced incorrectly?

This is how the info is being displayed:

Code:
while( $fetch = $query->fetch_array() )
		{
		
			//ukey($fetch['key'],$fetch['content']);
			echo
			("

shouts[n++] = \"<a href='http://" . getDomain( $fetch['key'] ) . "profile/" . $fetch['userid'] . "'>" . $fetch['username'] . "</a> -- <span style='color: " . $fetch['color'] . "'> " . getEmoticons($fetch['key'],$fetch['content']) . " </span> \"	
			");
		}
Its a shoutbox, but I'm still getting confused on why the output is very inaccurate? Is this because of php 5.2.4?

Example SQL result looks like so:

Code:
CREATE TABLE `zbemoticons` (
  `id` int(255) NOT NULL auto_increment,
  `userkey` varchar(255) NOT NULL,
  `text` varchar(255) NOT NULL,
  `image` longtext NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=18 ;

--
-- Dumping data for table `zbemoticons`
--

INSERT INTO `zbemoticons` VALUES(1, '2e64da0bae6a7533021c760d4ba5d6', ']-)', 'http://norvisions.info/emoticons/devlish.gif');
INSERT INTO `zbemoticons` VALUES(2, '2e64da0bae6a7533021c760d4ba5d6', 'hehe', 'http://norvisions.info/emoticons/hehe.gif');
INSERT INTO `zbemoticons` VALUES(3, '2e64da0bae6a7533021c760d4ba5d6', 'B-)', 'http://norvisions.info/emoticons/cool.gif');
INSERT INTO `zbemoticons` VALUES(4, '2e64da0bae6a7533021c760d4ba5d6', 'nor', 'http://norvisions.info/emoticons/evilgrin.gif');
So I don't see how its even getting messed up. Note I had it using just the whole look before adding the fetch to the db, and I noticed that way and the current way I'm selecting the data isn't the problem.

This is getting retarded -.-..

Was debugging: Ustore
__________________
PHP/XHTML Freelancer:
Cleanscript.com v3 - Programming starting at just $5 act now!
Nor is offline  
Reply With Quote