knight47 Posted March 11, 2007 Share Posted March 11, 2007 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 More sharing options...
jeremywesselman Posted March 11, 2007 Share Posted March 11, 2007 That is probably it. Why don't you add them before hand and output as one var and see what happens. Link to comment https://forums.phpfreaks.com/topic/42193-strange-problem-with-concatenation/#findComment-204682 Share on other sites More sharing options...
knight47 Posted March 11, 2007 Author Share Posted March 11, 2007 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 https://forums.phpfreaks.com/topic/42193-strange-problem-with-concatenation/#findComment-204951 Share on other sites More sharing options...
Orio Posted March 11, 2007 Share Posted March 11, 2007 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 https://forums.phpfreaks.com/topic/42193-strange-problem-with-concatenation/#findComment-204954 Share on other sites More sharing options...
designationlocutus Posted March 11, 2007 Share Posted March 11, 2007 Calculate it beforehand and then place it into the statement as a variable. Im guessing that its evaluating it as a none string and cannot echo it. Link to comment https://forums.phpfreaks.com/topic/42193-strange-problem-with-concatenation/#findComment-204957 Share on other sites More sharing options...
knight47 Posted March 11, 2007 Author Share Posted March 11, 2007 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 https://forums.phpfreaks.com/topic/42193-strange-problem-with-concatenation/#findComment-205001 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.