View Full Version : search the files
07-30-2012, 07:49 PM
i have around 1000 php files and some of these files contains category number like this
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
07-30-2012, 08:11 PM
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.
07-30-2012, 08:46 PM
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:
i want to search the file line by line and get this line ($cat_nu=10;) in a variable
07-30-2012, 08:58 PM
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.
07-30-2012, 09:39 PM
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.
Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.