PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
The Bullet Wives - Official Site - http://www.themiamovie.com/
Beat Kids - Official Site - http://www.beatkids.com/
Initial D - Official Site - http://www.initialdthemovie.com/
How about a file iterator. That will spit out one line at a time, simplifying the regex problem. In fact that might eliminate the need for regex altogether.
Next step would be to decorate the file iterator with a method which processes each line into an array. The essence of this could be:
McGruff wrote:How about a file iterator. That will spit out one line at a time, simplifying the regex problem. In fact that might eliminate the need for regex altogether.
Next step would be to decorate the file iterator with a method which processes each line into an array. The essence of this could be:
The Bul - let Wives - Official Site - http://www.themiamovie.com/
Beat Kids - Official Site - http://www.beatkids.com/
Initial D - Official Site - http://www.initialdthemovie.com/
but if you are 100% sure that you can rely on "<space><dash><space>" than you should be okay...
// initialize
$aray = array();
$count = 0;
// set the array keys to be used
$keys = array('movie','caption','link');
// do the file thing...
$file = file("../Links.txt");
// loop for every line
foreach ($file as $line) {
// convert line string to array
$details = explode('-',$line);
// loop 3 times
for($x=0;$x<3;$x++){
// use the value of $x to set the key and the values
// so that $keys[0] which is 'movies' will have
// a value of $details[0] which is 'The Bullet Wives'
// and so on...
$aray[++$count][$keys[$x]] = $details[$x];
}
}
Although you can loop through a file one line at a time using a file() array, you have to read the whole (multi-megabyte?) file into memory. With an iterator, you're only reading one line at a time.