Simple if/else - my brain is fried

Hi Guys,

I wonder if someone could put me right on this - what is surely really simple - if/else statement?

<?php if ($prop['img_main'] == 'none') { 
echo '<img src="../admin/img_management/none.jpg"/>'; 
else { 
echo '<img src="../admin/img_management/fileupload/uploads/' . htmlout($prop['img_main']) . '"' . 'width="188" height="128"/>'; 
} ?>

I just can’t see where I’m going wrong - been staring at it for too long.

Thanks in advance for any pointers. Sure it’s something really simple! :slight_smile:



Sorry, I didn’t say what the problem is:

Basically, when $prop[‘img_main’] isn’t ‘none’ (ie. it has a value), the output source code to locate the actual image it’s trying to reference is all back to front:

<div class=“mainimg-container”>
87959_gel033_img_00_0000_max_620x414.jpg<img src="…/admin/img_management/fileupload/uploads/"width=“188” height=“128”/>

It works a treat if the $prop[‘img_main’] is ‘none’, however!

What does your htmlout() function do?

If you simply just echo $prop[‘img_main’], what do you get for output? Is there actually a value, or is the value getting stripped by the htmlout() function?

Hey thanks for replying :slight_smile:
The htmlout() function does this:

	//Forces htmlspecialchars
function html($text)
	return htmlspecialchars($text, ENT_QUOTES, 'UTF-8');

function htmlout($text)
	echo html($text);

But the output is there - in the sourcecode I put - in both the !=‘none’ and other value.

Am I making sense?


Any ideas, anyone?

Its because you are echo’ing from the function AND in the if/else

Change your function to:

function htmlout($text)
    return html($text);

and it should be fine

Thanks for your reply - while that worked for the image, all of the dynamic text on the site (outputted from the db) now isn’t working.

I found a workaround as being:

  1. Leave the function alone
  2. Re-format the if/else statement to remove “htmlout(” before the “$prop[‘img_main’]” array output.

So the new, working if/else currently looks like:

    <?php if ($prop['img_main'] == 'none') { echo '<img src="../admin/img_management/none.jpg"/>'; }
	else { echo '<img src="../admin/img_management/fileupload/uploads/' . $prop['img_main'] . '"' . 'width="188" height="128"/>'; } ?>

Is this safe, to have removed the htmlout() function, do you think?

Thanks :slight_smile: