how to remove first line from a variable consists of multi lines ?

Discussion in 'PHP' started by ramysarwat, Dec 31, 2009.

  1. #1
    how to remove first line from a variable consists of multi lines ?
     
    ramysarwat, Dec 31, 2009 IP
  2. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #2
    preg_replace
    PHP:
    If you post the code explaining what you need removed someone or myself will give you a better idea.

    preg_replace can find something and replace it with something else or nothing, even // so its not read.
     
    MyVodaFone, Dec 31, 2009 IP
  3. ramysarwat

    ramysarwat Peon

    Messages:
    164
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    i want to gat page content using file_get_contents and then remove the first line from it
     
    ramysarwat, Dec 31, 2009 IP
  4. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #4
    Like I said if you post a snippet of code we can help you better.
    Anyway something like this, would remove for example the <title> name from google.com
    
    <?php 
    
    $content = file_get_contents("http://www.google.com");
    $final_page = preg_replace('#<title>(.*?)</title>#','<title></title>',$content);
    echo $final_page;
    
    ?>
    
    PHP:
    or in your case but I am not sure;
    This would comment out // a variable from been read

    
    <?php 
    
    $content = file_get_contents("http://www.someWebSite.com");
    $final_page = preg_replace('#$variable = "(.*?)";#','//$variable = "(.*?)";',$content);
    echo $final_page;
    
    ?>
    
    PHP:
     
    Last edited: Dec 31, 2009
    MyVodaFone, Dec 31, 2009 IP
  5. Kaimi

    Kaimi Peon

    Messages:
    60
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Regexp for removing first line....
    Easy way:
    
    <?php
    $data = file_get_contents('http://site.com/');
    $wo_first_line = substr($data, strpos($data, "\n"));
    print $wo_first_line;
    ?>
    
    PHP:
     
    Kaimi, Dec 31, 2009 IP