Jump to content

str_replace - problem with img


web_master

Recommended Posts

Hi,

 

I got 2 "str_replace"-es in script.

 

One is for a smilies and looks like: $s = str_replace(": )","<img src=\"media/icons/smilie_01.gif\">", $s);

 

The other is: $s = str_replace(".",". ", $s);

 

Well, when I add the latest str_replace (dot change to dot+space) the images is dissapears... :(

 

In source code the image src looks like this: <img src="media/icons/smilie_01.%20gif">

 

What can I do, to str_replace don't chande the dot to dot+space in img - "smilie_01.gif -> smilie_01.%20gif"?

 

Thanx in advanced!!!

Link to comment
https://forums.phpfreaks.com/topic/71778-str_replace-problem-with-img/
Share on other sites

you will be breaking the url as whitespace in a url is not allowed. as all characters need to be present the " " (space) is substiuted by %20

 

Give me the RAW data presumably $s before you manipulate it and give me what you WANT the output to be.  And as the last poster said....if you DO need a space, please advise WHY

 

Will

well...

 

This changes is for a better look of shout-box.

 

The shout boxes width is given. But lots of a visitors when read texts forgot to insert the space after the dot (and comma). This result somethimes the very wide "word". And this result that a shout-box need a scrollink when You want to read this text.

 

As You see this will be a "cosmetic" only.

<?php
$query_shout_return = mysql_query ("SELECT * FROM `shout_box` WHERE shout_mutat = '1' ORDER BY `shout_id` DESC LIMIT 0, 30");

	if(!$query_shout_return) {
		print mysql_error();
		exit;
	}

while($request_shout_return = mysql_fetch_array($query_shout_return)) {

	$s = nl2br($request_shout_return['shout_txt']);
	$s = str_replace(": )","<img src=\"media/icons/smilie_01.gif\">", $s);
	$s = str_replace(":-)","<img src=\"media/icons/smilie_01.gif\">", $s);
	$s = str_replace(": (","<img src=\"media/icons/smilie_02.gif\">", $s);
	$s = str_replace(":-(","<img src=\"media/icons/smilie_02.gif\">", $s);
	$s = str_replace(": D","<img src=\"media/icons/smilie_03.gif\">", $s);
	$s = str_replace(",",", ", $s);
?>

 

$s is a shout-boxes text

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.