Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8463665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T14:31:08+00:00 2026-06-10T14:31:08+00:00

The test.php directory is the same as csv and text file. now i want

  • 0

The test.php directory is the same as csv and text file. now i want to pass all the csv file name and all the text name to the following if condition. namely, replace one.csv with all the csv file name. replace one.txt with all the txt file name.

if (($handle = fopen("one.csv", "r")) !== FALSE && ($handle2 = fopen("one.txt", 'a')) !== FALSE) { ...}

the following is my code. after run the code,i found all the content in the text file are the same. it loops too many times. how to change the code?thank you.

    $files = glob("./*.csv");
    $files1 = glob("./*.txt");
    foreach($files as $filepath){
    foreach($files1 as $filepath1){


   $row = 1;
if (($handle = fopen("one.csv", "r")) !== FALSE && ($handle2 = fopen("one.txt", 'a')) !== FALSE) {
    while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
        if($row > 1) {
            $url = $data[8];
            foreach($result[0] as $url){
                fwrite($handle2, $url."\r\n");
            }

        }
        $row++;
    }
    fclose($handle);
    fclose($handle2);
}

    }
    }

The txt file is empty. now, i want to read the csv file and extract some content of it then put them into the text file. thank you

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T14:31:10+00:00Added an answer on June 10, 2026 at 2:31 pm

    You don’t need to glob .txt files, just glob csv, and replace the extension .csv by .txt

    $csv = glob('./*.csv');
    foreach($csv as $file) {
       $txt = preg_replace('#\.csv$#', '.txt', $file);
       if (($handle = fopen($file, "r")) !== FALSE && ($handle2 = fopen($txt, 'a')) !== FALSE) {
        //your code...
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My test.php file contains the following information that is sends list of information. while($row
I have a button on a file test.php <?php $url=http://.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; ?> <input type=button name=btn
I have two php files in the same directory: test.tattler.php class.tattler_stats.php My test.tattler is
The script below, test.php, is intended to be placed in a specific directory of
Page1 : test.php (open in popup) <script type=text/javascript> function addFiles(aFiles) { if ($('#addfiles').length==0) $('#addfiles').html;
I want to redirect using .htaccess abc.com/test.php to abc.com/test . but it will execute/display
Please consider the following URLs: http://www.mydomain.com/a/test.php https://www.mydomain.org/a/b/test.php http://www.mydomain.co.nr/a/b/c/test.php https://www.mydomain.com/a/b/c/d/test.php http://www.mydomain.co.uk/a/b/c/d/e/test.php https://www.mydomain.co.au.nm/a/b/c/d/e/f/test.php?var1=test1&var2=test2 Now I want
I currently have my 'WebSocketMain.swf' file sitting in the same directory as 'socket.io.min.js' but
The end goal is for the user to download a .csv file. Right now
This is my phpunit test file <?php // DemoTest - test to prove the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.