Jump to content

strange problem with . concatenation


knight47

Recommended Posts

Does anyone know why this script won't properly work?

 

It actually does work, but it's giving me a problem with the lines commented below:

 

<?php

$htm = glob('*.htm');
$html = glob('*.html');
$php = glob('*.php');
$jpg = glob('*.jpg');
$jpeg = glob('*.jpeg');
$xml = glob('*.xml');
$swf = glob('*.swf');
$gif = glob('*.gif');


$add_all = count($htm) + count($html) + count($php) + count($jpg) + count($jpeg) + count($xml) + count($swf) + count($gif);


echo "There are " . count($htm) + count($html) . " HTML files <br /><br />"; // it seems to ignore the "There are " part

echo "There are " . count($php) . " php files <br /><br />";

echo "There are " . count($jpg) + count(jpeg) . " jpeg files <br /><br />"; // Same with the first one, is it because I'm adding them? Why would this hinder it's output??

echo "There are " . count($swf) . " swf files <br /><br />";

echo "There are " . count($gif) . " gif files <br /><br />";

echo "There are " . count($xml) . " xml files <br /><br />";


echo "Total: $add_all";



?>

 

View it here to understand what I'm talking about: www.knight47.com/files.php

 

Why is it not displaying the "There are " for the HTML and jpg files?

 

Thanks again.

Link to comment
https://forums.phpfreaks.com/topic/42193-strange-problem-with-concatenation/
Share on other sites

That is probably it. Why don't you add them before hand and output as one var and see what happens.

yeah that does work, but i'm wondering why it's not working in my case above, I would like to know why so I won't get into the same problem in future cases.

I also had problems when I tried once to echo and calculate in the same line. Put the calculation in parentheses and see if you still have problems:

 

echo "There are " . (count($htm) + count($html)) . " HTML files <br /><br />";

 

 

Orio.

Yup, that seemed to work, thanks!

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.