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.

What i do after using foreach loop get similer result

Discussion in 'Programming' started by ironmankho, Jul 26, 2011.

  1. #1
    Hi !

    i am working this code ...basically this code using php explode to get required data
    like

    Net com-1
    SEMrush
    from this line
    <span class=company>Net com-1</span>

    here is my code:

    <?php
    $data=file_get_contents('http://www.webtjax.com/test.txt');
    $line_title=explode('<span class=company>',$data); 
    unset ($line_title[0]);
    foreach($line_title as $part) {
    $line_title_temp=explode('</span>',$part);
    echo $line_title_temp[0].'<br />' ; 
                                  } 
    ?>
    PHP:
    Now i successfully get the end result i have no problem .....

    but i am failed in this step when i use this with 2 code like


    <?php
    $data=file_get_contents('http://www.webtjax.com/test.txt');
    /////****************************************************
    $line_title=explode('true);" title="',$data); 
    unset ($line_title[0]);
    foreach($line_title as $part) {
    $line_title_temp=explode('">',$part);
    echo $line_title_temp[0].'<br />' ; 
    }
    /////***************************************************
    echo '<h1>= = = = =  </h1>' ;
    ////****************************************************
    $line_title=explode('<span class=company>',$data); 
    unset ($line_title[0]);
    foreach($line_title as $part) {
    $line_title_temp=explode('</span>',$part);
    echo $line_title_temp[0].'<br />' ; 
    }
    /////****************************************************
    ?>
    PHP:
    this will get this result

    Webmaster-1
    Webmaster-2
    Webmaster-3
    Webmaster-4
    Webmaster-5
    Webmaster-6
    Webmaster-7
    Webmaster-8
    Webmaster-9
    Webmaster-10
    = = = = =
    Net com-1
    Net com-2
    Net com-3
    Net com-4
    Net com-5
    Net com-6
    Net com-7
    Net com-8
    Net com-9


    Now my question is that How i can add this two variable like this

    But i have no idea how i can done ...?
     
    Solved! View solution.
    ironmankho, Jul 26, 2011 IP
    SEMrush
  2. n3r0x

    n3r0x Well-Known Member

    Messages:
    257
    Likes Received:
    4
    Best Answers:
    1
    Trophy Points:
    120
    #2
    This works

    
    <?php
    $data=file_get_contents('http://www.webtjax.com/test.txt');
    /////****************************************************
    $line_title=explode('true);" title="',$data);
    unset ($line_title[0]);
    $x = 0;
    foreach($line_title as $part) {
    	$temp=explode('">',$part);
    	$part_1[$x] = $temp[0];
    	$x++;
    }
    /////***************************************************
    
    ////****************************************************
    $line_title=explode('<span class=company>',$data);
    $x = 0;
    unset ($line_title[0]);
    foreach($line_title as $part) {
    $temp =explode('</span>',$part);
     $part_2[$x] = $temp[0];
     $x++;
    }
    /////****************************************************
    
    $y = 0;
    while($y <= $x) {
    	echo $part_1[$y] ." @ ".$part_2[$y]."<br />"; 
    	$y++;
    }
    ?>
    
    PHP:
    But im sure there´s a better way
     
    n3r0x, Jul 26, 2011 IP
  3. ironmankho

    ironmankho Active Member

    Messages:
    394
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    55
    #3
    Thanks for this ...it realy works that i want but end result is why like that ...one is missing

    Webmaster-1 @ Net com-1
    Webmaster-2 @ Net com-2
    Webmaster-3 @ Net com-3
    Webmaster-4 @ Net com-4
    Webmaster-5 @ Net com-5
    Webmaster-6 @ Net com-6
    Webmaster-7 @ Net com-7
    Webmaster-8 @ Net com-8
    Webmaster-9 @ Net com-9
    Webmaster-10 @
     
    ironmankho, Jul 27, 2011 IP
  4. #4
    no wonder since the textfile is:


    the textfile is missing Net com-10
     
    n3r0x, Jul 27, 2011 IP
  5. ironmankho

    ironmankho Active Member

    Messages:
    394
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    55
    #5
    Thanks for this... i Know that it is my mistake......
     
    ironmankho, Jul 27, 2011 IP