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
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.
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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!
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.