将长篇文章分解为数组

时间:2014-06-10 05:15:32

标签: php arrays explode implode

我在mysql db中有longtext列,想要将它分解为数组。但是爆炸只返回1个字符串。

$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/    

3 个答案:

答案 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

答案 1 :(得分:1)

在第三行中,您使用了错误的变量名$test_string,您应该使用$temp_string

答案 2 :(得分:-1)

尝试使用 ;

之类的分隔内容进行内爆和爆炸
    $temp_string = implode(";", $temp_array_links); //convert array to string
    $info_array_links = explode(";", $temp_string); //explode string