0

The following code appears to do nothing

<?php 
    $packages = fopen("packages.txt", "r");
    $packs = fread($packages, filesize("packages.txt"));
    $pack = explode(" ", $packs);
    fileclose("packages.txt");

    $packageCount = count($pack);
    echo "<script>console.log('" . $packs . "');</script>";
    for ($i=0; $i<$packageCount; $i++) {
        echo $pack[$i];
        echo "<p>" . $pack[$i] . "</p>";
    }
?>

It may look bad, but keep in mind I've just started learning PHP. For some reason, this doesn't appear to do anything. All these echos don't do anything. This is in a <body> tag, and it doesn't have any errors. I have html objects after this PHP code, but it doesn't do anything, it's like this PHP block stops everything from working. I'm trying to make a text file store things just so I can learn, and this isn't doing anything. Any assistance will be appreciated from the new guy.

That1nub
  • 11
  • 5
  • how are you rendering this? – PlayMa256 Aug 03 '18 at 00:32
  • 1
    `fileclose` should be `fclose`. See the "duplicate" I just flagged - there are other posts on how to show errors etc. – Robbie Aug 03 '18 at 00:33
  • @Robbie: typo in your comment above ;) – gview Aug 03 '18 at 00:34
  • @gview - Thanks - was editing. – Robbie Aug 03 '18 at 00:35
  • 1
    Thank you @Robbie it started working after this.. I'm an idiot. Again, new to PHP, these will happen. I am sorry for making this post when it was unnecessary. – That1nub Aug 03 '18 at 00:36
  • See Robbies comments. You have a runtime error, but you're not displaying it. Key to debugging is displaying errors. You never got to your console log statement. You also might want to look into this: https://chrome.google.com/webstore/detail/php-console/nfhmhhlpfleoednkpnnnkolmclajemef?hl=en – gview Aug 03 '18 at 00:37
  • @Robbie The duplicate you chose was good, *but* it doesn't fully answer the question, which by closing a question with one is (IMHO) should also solve the question. I did however keep yours and added another to it which would be a follow-up to it and would cover all the bases, as it were. ;-) – Funk Forty Niner Aug 03 '18 at 00:44
  • @FunkFortyNiner - the top answer of the duplicate I flagged would have revealed the problem - user had no error displayed and needed it to be displayed which could be fixed using those post. Having said that - suggest OP read both for debugging! Cheers. – Robbie Aug 03 '18 at 01:28
  • @Robbie Sure, no problemo :-) I just couldn't find "undefined function" inside your choice of dupe, as it does in the other I added. But yeah, debugging is definitely something that needs to be done and if not, by learning how and learning how to interpret them correctly :-) *Cheers* – Funk Forty Niner Aug 03 '18 at 01:32

0 Answers0