Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Dec 2010
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts

    search the files

    i have around 1000 php files and some of these files contains category number like this
    $cat_nu=10;

    and this number is different in each page that contains the variable , what i want is to search these files and collect these numbers in array ,

    can any one help me please

  • #2
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,536
    Thanks
    45
    Thanked 259 Times in 256 Posts
    The glob function might be the way to go, but searching through a lot of files is going to be very slow.

    Whats the end purpose... you want to display how many items in each category? A database, even a flat file database, may be the best way for that... counting files every time someone loads a page is really gonna tax your server.

  • #3
    New Coder
    Join Date
    Dec 2010
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thank you keleth , but i think the glob function is used to search for file in the directory based on their extension , i will explain to you more what i need



    suppose you have a file that contains this line:
    $cat_nu=10;

    i want to search the file line by line and get this line ($cat_nu=10 in a variable

  • #4
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,536
    Thanks
    45
    Thanked 259 Times in 256 Posts
    Well, you'd use glob to get all the files, then something like fread to get the data out, then regex to get the values.

    It'll be REALLY slow.

  • #5
    Senior Coder
    Join Date
    Sep 2010
    Posts
    2,020
    Thanks
    15
    Thanked 239 Times in 239 Posts
    This sounds like a job for a shell script. If you're on any of the 'nixes, including Mac, you can write a shell script that will do this in a few minutes. Along with whatever shell commands you want to include, such as listing the files, you need a little application named sed, the Stream Editor. It can append all the lines that contain a certain string to a file, among many other things it can do, and you can modify that file however you like.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •