Any php gurus here? Array_walk help needed

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • smashface
    Confirmed User
    • Sep 2002
    • 991

    #1

    Any php gurus here? Array_walk help needed

    Im trying to create a file by using each element of an array as the filename. I have the following code and am getting an Invalid argument error.

    $newfile = file("newdata.txt");

    function touchfile($foo) {

    touch($foo);

    }

    array_map ("touchfile", $newfile);

    The error is occurring in the touch line.

    Any suggestions are appreciated.

    Chris
  • swedguy
    Confirmed User
    • Jan 2002
    • 7981

    #2
    HAve you checled what newdata.txt contains?

    Comment

    • swedguy
      Confirmed User
      • Jan 2002
      • 7981

      #3
      edit....

      Comment

      • Spudstr
        Confirmed User
        • Jan 2003
        • 2321

        #4
        sure your permissions are alright?
        Managed Hosting - Colocation - Network Services
        Yellow Fiber Networks
        icq: 19876563

        Comment

        • smashface
          Confirmed User
          • Sep 2002
          • 991

          #5
          Originally posted by swedguy
          HAve you checled what newdata.txt contains?
          it contains the text I want

          ex. foo.html
          foo1.html

          Comment

          • smashface
            Confirmed User
            • Sep 2002
            • 991

            #6
            Originally posted by Spudstr
            sure your permissions are alright?
            Im testing on a Windows machine using Abyss Webserver plus PHP5. I'm able to get a literal value to be the filename. If I change;

            touch($foo);

            to

            touch('$foo');

            it will create the file $foo

            Comment

            • swedguy
              Confirmed User
              • Jan 2002
              • 7981

              #7
              This works:

              Code:
              <?php
              
              $newfile = file("test.txt");
              
              function touchfile($foo) {
              	$foo = trim($foo);
              	touch($foo);
              }
              array_walk($newfile, 'touchfile');
              ?>

              Comment

              • woj
                <&(©¿©)&>
                • Jul 2002
                • 47882

                #8
                what's the error you are getting?
                Custom Software Development, email: woj#at#wojfun#.#com to discuss details or skype: wojl2000 or gchat: wojfun or telegram: wojl2000
                Affiliate program tools: Hosted Galleries Manager Banner Manager Video Manager
                Wordpress Affiliate Plugin Pic/Movie of the Day Fansign Generator Zip Manager

                Comment

                • smashface
                  Confirmed User
                  • Sep 2002
                  • 991

                  #9
                  Thanks swedguy. I guess there was a space/carriage return that was causing an error.

                  Comment

                  • swedguy
                    Confirmed User
                    • Jan 2002
                    • 7981

                    #10
                    Hmm, just adding double quotes on the trim() in the original code works too. Odd.

                    Comment

                    Working...