Current location: Hot Scripts Forums » Programming Languages » PHP » pull code from a file


pull code from a file

Reply
  #1 (permalink)  
Old 10-02-04, 01:33 PM
nassau nassau is offline
Wannabe Coder
 
Join Date: May 2004
Posts: 211
Thanks: 0
Thanked 0 Times in 0 Posts
pull code from a file

i have a webpage with my own music on it.

i want to be able to make a text file containing the names of the songs, and have a PHP function in the index.php file access the text file and pull whatever content is in there.

let's say the text file looks like this:

song number one
track number two
tune number three
beat number four

i want the function to go though all the song names, couple them with the neccesary <a href> and mp3 data and display them on a page. the function needs to loop through the song names from beginning to end, regardless of the number of names.

i'm guessing the song name file could look something like this:

$item1= song number one
$item2= track number two
$item3= tune number three
$item4= beat number four

this is just an example, i don't know anything about $ and this type of php code so don't take it literary.
Reply With Quote
  #2 (permalink)  
Old 10-02-04, 11:14 PM
sufyan sufyan is offline
Newbie Coder
 
Join Date: Jun 2003
Location: Melbourne, AU
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
You could have something like:

PHP Code:

<?

$songs 
file('./songs.txt');
foreach (
$songs as $song_num => $song)
{
    echo 
'<a href="' htmlspecialchars($song) . '.mp3">' $song_num ': ' htmlspecialchars($song) . '</a><br />';
}
?>
__________________
suf.id.au
Reply With Quote
  #3 (permalink)  
Old 10-03-04, 04:04 AM
nassau nassau is offline
Wannabe Coder
 
Join Date: May 2004
Posts: 211
Thanks: 0
Thanked 0 Times in 0 Posts
ok, thanks!
would you mind explain what the different functions do? like "$songs", "$song_num", "htmlspecialchars" etc. i can prolly figure it out but if u want to explain it would be great!

i'm a total newbie so please bear with me
Reply With Quote
  #4 (permalink)  
Old 10-03-04, 05:40 AM
sufyan sufyan is offline
Newbie Coder
 
Join Date: Jun 2003
Location: Melbourne, AU
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
No problems.

As for what each function does, The PHP manual is very handy. Just go to php.net and enter a function in the text box on the top right hand corner and it'll tell you about that specific function.

For example, type in htmlspecialchars, and you should be taken to: http://au2.php.net/manual/en/control...es.foreach.php

$songs and $song_num are variables. To find out what they represent, look up the 'foreach' construct (the same way you would look up a function).

Hope this help. If you have any other question feel free to post them here.
__________________
suf.id.au
Reply With Quote
  #5 (permalink)  
Old 10-03-04, 10:18 PM
nassau nassau is offline
Wannabe Coder
 
Join Date: May 2004
Posts: 211
Thanks: 0
Thanked 0 Times in 0 Posts
hmm, i got "parse error"... i wonder what i'm doing wrong...
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP code to edit a text file mdhall Script Requests 12 12-23-10 04:03 AM
Make this code pull random pictures?! APuppyDog PHP 3 08-26-04 05:13 PM
Overwrite an mdb file brandodotnet Script Requests 1 08-03-04 05:28 PM
PHP code on a remote file tonniar .rm PHP 2 05-24-04 02:32 AM
Getting the created file (fopen/fwrite) Programme PHP 5 02-14-04 03:09 PM


All times are GMT -5. The time now is 04:34 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.