Solved PHP Question

Solved issue


New Member
Dec 21, 2021
Reaction score
You guys did such a great job getting me to run thru what must've happened last time, I thought I'd do it again 8 )__.
I'm using PHP in Included file to run thru the file system and print the .txt files, therein, to screen and I am baffled. It seems to want to print every file & below 100 words ( a no-no). Below is the script (variables made clearer). I just thought to use $wCount (doesn't work either) in Switch but I'd still like to know why this won't work {8 ]__. thank you for your input
[this is funny :
i put echo "hello > 100 !"; in the case true, and, it only printed it in those greater than 100 ; >]
phfff ! I had some html tags in one of the .txt files (removed tags and fixed the problem)!! I thought i'd leave this up a few days to let others know what could happen (so, simple)
<?php echo mains();
function mains(){
global $scan=(the scanned folder/for text files);
global $br="<br/>";
global $hr="<hr size='10'>";
foreach($scan as $a){
case true:
echo $wCount.$br;
echo $reading.$br.$hr;break;}}}} ?>
Last edited:

Maybe something like this might work:

<?php $folderPath = '/home/ubuntu/test'; $br = PHP_EOL; $hr = "<hr size='10'>"; $files = glob($folderPath . '/*.txt'); foreach ($files as $file) { $reading = file_get_contents($file); $wordCount = str_word_count($reading); if ($wordCount > 100) { echo "File: $file$br"; echo "Word Count: $wordCount$br$br"; } } ?>
This seems to work when I test this script out in my lab. These are the steps I took:
  1. Define the folder path where the text files are going to reside
  2. Lines breaks when outputting the results
  3. The array $files defines a glob() function to fetch an array of file paths that much the pattern (.txt files)
  4. A foreach loop to iterate over each file in the $file array
Hello. Welcome to the forum.

Why is this under General Server?

For some reason, they edited their question. They did so multiple times.

I'm just going to close the thread. There's not much hope of salvaging it.
I have reverted this to the way it should be and am moving it to Command Line.

@chlyde please don't delete or edit to mean nothing your first Posts in future.


I have reverted this to the way it should be and am moving it to Command Line.

LOL I thought about doing that but couldn't decide which edit was best and figured, while horribly annoying, a user can edit their post so long as it doesn't violate the rules.

I suppose we can use this as precedent as this isn't the first time this has happened.

Members online