Reading data from a txt file !!

Discussion in 'PHP' started by omaryo, Feb 9, 2008.

  1. #1
    Hey i have a txt file and i wanna retrieve data from it using php
    my txt file is :
    50 CENT|http://www.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xx
    2 PAC|http://www.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xx
    Antonio garcia|http://www.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xx
    ABBA|http://www.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xx
    BSB|http://www.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xx
    BEYONCE|http://www.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xx
    ........
    i wanna retrieve every group of artists that begins with specific letter
    and every artist links to his link !!
    thanks
     
    omaryo, Feb 9, 2008 IP
  2. imvain2

    imvain2 Peon

    Messages:
    218
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #2
    It would be best to use a database, however if you have to use a txt file.

    
    <?
    $lines = file('myfile.txt');
    
    $letter = "C";
    
    foreach ($lines as $line) {
    	$arry = explode("|",$line);
    	$artist = $arry[0];
    	$url = $arry[1];
    	if(strtolower(substr($artist,0,1))== strtolower($letter)){
    		echo  $url . "<br>";		
    	}
       }
    ?>
    
    PHP:
     
    imvain2, Feb 9, 2008 IP
  3. mab

    mab Active Member

    Messages:
    563
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    80
    #3
    mab, Feb 10, 2008 IP
  4. omaryo

    omaryo Well-Known Member

    Messages:
    1,218
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    140
    #4
    Thanks imvain2 the code is working .
    it is easy to add pagination to this code ??
     
    omaryo, Feb 18, 2008 IP