...

View Full Version : php get second word from file



bizkit1
11-15-2011, 08:22 PM
hello. So here is my .txt file:



"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

mlseim
11-15-2011, 08:49 PM
<?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 />";
}
?>

bizkit1
11-15-2011, 08:54 PM
it works...thank you very much!

mlseim
11-15-2011, 11:21 PM
an FYI for you ... $parts[1] is the first word.


.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum