Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Oct 2011
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    php get second word from file

    hello. So here is my .txt file:

    Code:
    "zaharia" "27"
    "White And Proud" "553"
    "Adytzu" "1084"
    "OzzY" "1101"
    "SuPeR BrEaK DaNcE" "7085"
    "d3nn!s" "3698"
    "cs.radiozu.ro" "609"
    "empty" "35"
    "$XxX$" "412"
    "Cokhalte^" "851"
    "cs.radiozu.ro-player" "326"
    "eminem" "2981"
    "|Familly*}bOYS-*Sar]rke-" "1461"
    "[Gag] [Enk]^BaNNNaNNNaJOoY^[cL]" "7750"
    "Pac-Pac" "6691"
    "Mr.B0ne" "511"
    "AmericanMan" "28"
    "3D" "2458"
    "make" "1233"
    "SuPeR" "2241"
    "R4iN M4N" "904"
    "jupiter" "2233"
    "sc*ry mov!e" "950"
    "SEAL alberto1" "2158"
    "SkittleS" "6794"
    "BALTI/k" "2218"
    "lam.umilit.pe.->" "878"
    "NeVeR BaCk DoWn" "1777"

    I need a php script that reads this file and outputs only the second word between "" from each line. So it should look like this:

    27
    553
    1084
    .
    .
    .

    Thanks

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,549
    Thanks
    8
    Thanked 1,095 Times in 1,086 Posts
    PHP Code:
    <?php

    // put file into array by lines
    $data=file("mytext.txt");

    // loop through each line
    foreach($data as $line){

    // explode the line by quotes
    $parts=explode("\"",$line);

    // echo value ... or do whatever you want
    echo $parts[3]."<br />";
    }
    ?>

  • #3
    New Coder
    Join Date
    Oct 2011
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts
    it works...thank you very much!

  • #4
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,549
    Thanks
    8
    Thanked 1,095 Times in 1,086 Posts
    an FYI for you ... $parts[1] is the first word.


    .


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •