2016-05-13 14 views
0

socallink.txt:Array von file_get_contents() Wert

"Facebook", "Twitter", "Twitter", "google-plus", "youtube", "pinterest", "instagram"

PHP:

$file = file_get_contents('./Temp/socallink.txt', true); 
$a1 = array($file); 
print_r($a1); 

Ergebnis:

Array 
(
    [0] => "Facebook","Twitter","Twitter","google-plus","youtube","pinterest","instagram" 
) 
Benötigte 0

:

$a1['0']=facebook; 
$a1['1']=Twitter; 

Antwort

2

Dies löst Ihr Problem:

$file = '"Facebook","Twitter","Twitter","googleplus","youtube","pinterest","instagram"'; // This is your file 

Entfernen Sie zuerst alle“.

$file = str_replace('"', '', $file); 

Dann wird bei jeder Explosion,

$array = explode(',',$file); 

var_dump($array) gibt:

array(7) { 
    [0]=> 
    string(8) "Facebook" 
    [1]=> 
    string(7) "Twitter" 
    [2]=> 
    string(7) "Twitter" 
    [3]=> 
    string(11) "google-plus" 
    [4]=> 
    string(7) "youtube" 
    [5]=> 
    string(9) "pinterest" 
    [6]=> 
    string(9) "instagram" 
} 

Globalen Code wie folgt aussieht:

$file = file_get_contents('./Temp/socallink.txt', true); 
$file = str_replace('"', '', $file); 
$a1 = explode(',',$file); 

Hope this

helfen wird
+0

Vielen Dank. habe einen guten Tag –

+0

Bitte als richtig markieren, was auch immer geantwortet hat, um den Feed zu reinigen – Unex

0

Da sind diejenigen, Comma Separated Values ​​(CSV), ist dies wahrscheinlich die einfachste wäre:

$file = file_get_contents('./Temp/socallink.txt', true); 
$a1 = str_getcsv($file); 
-1
<?php 
//fetch the file content 
    $file = file_get_contents('your file path`enter code here`'); 

//create an array by breaking the string into array values at the comma ',' point 
$a = explode(',',$file); 

print_r($a); 

//result 
// Array ([0] => "Facebook" 
// [1] => "Twitter" 
// [2] => "Twitter" 
// [3] => "google-plus" 
// [4] => "youtube" 
// [5] => "pinterest" 
// [6] => "instagram") 
+0

Was ist mit den Anführungszeichen? – AbraCadaver