2014-06-10 32 views
-2

我在mysql數據庫中有longtext列,並且想將其放入數組中。但爆炸返回我只有一個字符串。將長文本分解爲數組

$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

這不是一個MySQL的問題。 – shmosel

+0

數組(1){[0] =>字符串(58)「http://google.com/ http://test.com/ http://test1.com/」} – GONGOTA

回答

1

在第三行,你使用了錯誤的變量名$test_string,你應該使用$temp_string

+0

很好地發現。 +1 – hammus

+0

哦,它是在實驗後留下的,對不起,但問題沒有解決 – GONGOTA

+0

有時它打印出一個空白字符「」,但它實際上是一個「\ n」字符。你能檢查一下嗎?只需將「」替換爲「\ n」即可。 –

-1

嘗試破滅,並用分離像;

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

已經試過,沒有任何反應 – GONGOTA

+0

有你檢查了implode後你得到的字符串是什麼? –

+0

我認爲它的變量名稱 –

1

爆炸您$test_string應該$temp_string嘗試

$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); 

也爲獲取數組,你需要使用的索引數組不是$info_array_links[$user_id--]嘗試$info_array_links[0] // 1, 2,3

+0

嘗試返回與3個元素的完整字符串的問題 – GONGOTA

+0

嘗試print_r($ temp_array_links)並顯示您的結果 –