TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
 
 
LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
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
 



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 12:25 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design