2014-06-10 3 views
-2

J'ai une colonne longtext dans mysql db et je veux l'expliquer en tableau. Mais exploser me renvoie seulement 1 chaîne.Explose un longtext en tableau

$temp_array_links[] = $item->links; //array value: http://google.com/ http://test.com/ http://test1.com/ 
$temp_string = implode(" ", $temp_array_links); //convert array to string 
$info_array_links = explode(" ", $test_string); //explode string 
echo 'Your link: <a href="'. $info_array_links[$user_id--] .'">LINK</a>'; //should be http://google.com/ insted of http://google.com/ http://test.com/ http://test1.com/  
+0

Ce n'est pas une question mysql. – shmosel

+0

tableau (1) {[0] => chaîne (58) "http://google.com/ http://test.com/ http://test1.com/"} – GONGOTA

Répondre

1

Dans la troisième ligne, vous avez utilisé le mauvais nom de la variable $test_string, vous devriez avoir utilisé $temp_string

+0

Bien repéré. +1 – hammus

+0

oh, il est laissé après des expériences, désolé, mais le problème ne résout pas – GONGOTA

+0

Parfois, il est imprimé un caractère espace blanc "", mais il est en fait un caractère "\ n". Pourriez-vous vérifier cela? Remplacez simplement le "" par "\ n". –

-1

essayer d'imploser et exploser avec une chose séparée comme ;

$temp_string = implode(";", $temp_array_links); //convert array to string 
    $info_array_links = explode(";", $temp_string); //explode string 
+0

déjà essayé, rien ne se passe – GONGOTA

+0

avoir vous avez vérifié quelle est la chaîne que vous obtenez après imploser? –

+0

je pense que son problème avec le nom de la variable –

1

votre $test_string devrait être $temp_string essayer

$temp_array_links = array('http://google.com/', 'http://test.com/', 'http://test1.com/'); 
echo $temp_string = implode(" ", $temp_array_links); //convert array to string 
$info_array_links = explode(" ", $temp_string); //explode string 
print_r($info_array_links); 

également pour le tableau aller chercher, vous devez utiliser l'index de un tableau pas $info_array_links[$user_id--] essayer $info_array_links[0] // 1, 2,3

+0

essayé retourné la chaîne complète avec 3 éléments – GONGOTA

+0

essayez print_r ($ temp_array_links) et montrer votre résultat –