From text file to array
Posted: Thu Apr 28, 2005 4:25 pm
How, using regex, could i turn
which is stored in links.txt into the results of:
What I have so far:
Code: Select all
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/Code: Select all
$links = array();
$links[0] = array();
$links[0]["Movie"] = "The Bullet Wives";
$links[0]["Caption"] = "Official Site";
$links[0]["Link"] = "http://www.themiamovie.com/";
$links[1] = array();
$links[1]["Movie"] = "The Bullet Wives";
$links[1]["Caption"] = "Beat Kids";
$links[1]["Link"] = "http://www.beatkids.com/";
$links[2] = array();
$links[2]["Movie"] = "Initial D";
$links[2]["Caption"] = "Official Site";
$links[2]["Link"] = "http://www.initialdthemovie.com/";Code: Select all
$file = file_get_contents( "../Links.txt" );
$pattern = "/\n/";
$links = preg_split( $pattern, $file );
foreach ( $links as $link ) {
list( $movie, $caption, $link ) = preg_split( "/ - /", $link );
echo "<br>$movie: ($caption) $link";
}