Jump to content

Recommended Posts

I started taking a web development class and im having trouble running a loop that opens multiple files.

The files are label as so:

 

movie_review0.txt

movie_review1.txt

movie_review2.txt

movie_review3.txt

movie_review4.txt

 

We have to write a loop not knowing how many files there are in the folder. Does anyone have any suggestions? I've tried using a while loop but I dont think I have the syntax correct. Thanks

So I'm getting frustrated and tired and I know this is simple but I cant figure out how to do it. I have this array:

 

$files = Array ( [0] => tron_info.txt [1] => tron_review0.txt [2] => tron_review1.txt [3] => tron_review2.txt [4] => tron_review3.txt [5] => tron_review4.txt [6] => tron_review5.txt [7] => tron_review6.txt )

 

Now I need to remove anything that doesnt contain the word 'review'

 

I know this has to be simple but at this point im about to break my computer in half. Any help would be much appreciated.

You need to know something about wild-card filename matching in Linux (Unix).

 

I have these files in my directory:

tron_movie.txt
tron_review0.txt
tron_review1.txt
tron_review2.txt
tron_review3.txt
tron_review4.txt

Using this code

<?php
$x = glob('*review*.txt');
echo '<pre>' . print_r($x,true) . '</pre>';
?>

gets me


Array
(
    [0] => tron_review0.txt
    [1] => tron_review1.txt
    [2] => tron_review2.txt
    [3] => tron_review3.txt
    [4] => tron_review4.txt
)

 

Ken

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.