1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Problem with array

Discussion in 'PHP' started by ssimon171078, Nov 4, 2014.

  1. #1
    i need to print each element in array ,i wrote code in php .i need that in line : echo $line . "<br />"; i see each element in array but i see a problem convert it to string.

    <?php
    $website="https://www.tradebit.com/filesharing.php/1010-Documents-eBooks-Audio-Books-Teaching";
    
    //echo $website ;
    $content=file_get_contents($website);
    
    preg_match_all("/<a href=\"([^\"]*)\">(.*)<\/a>/iU",$content,$result);
    
    //print_r($result);
    foreach ($result as $line ){
    echo  $line . "<br />";
    }
    ?>
    Code (markup):

     
    Last edited by a moderator: Nov 4, 2014
    ssimon171078, Nov 4, 2014 IP
  2. sarahk

    sarahk iTamer Staff

    Messages:
    28,980
    Likes Received:
    4,572
    Best Answers:
    124
    Trophy Points:
    665
    #2
    what you have should be fine but you could try something like this too

    foreach($result as $line){
       echo "{$line}<br />";
    }
    Code (markup):
    The docs for preg_match_all state that $result[1] will actually hold the information that you need - but in another array

    so your code should be
    foreach($result[1] as $line){
       echo "{$line}<br />";
    }
    Code (markup):
    and if you want to be really tricky you could use

    echo implode("<br />", $result[1]);
    Code (markup):
     
    sarahk, Nov 4, 2014 IP