-2

I have longtext column in mysql db and want to expldoe it into array. But explode returns me only 1 string.

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

1

your $test_string should be $temp_string try

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

Also for fetching array you need to use index of an array not $info_array_links[$user_id--] try $info_array_links[0] // 1, 2,3

Rakesh Sharma
  • 13,680
  • 5
  • 37
  • 44
1

In the third line, you used the wrong variable name $test_string, you should have used $temp_string

Alexandre Justino
  • 1,716
  • 1
  • 19
  • 28
  • oh, it's left after experiments, sorry, but problem doesn't solve –  Jun 10 '14 at 05:23
  • Sometimes its printed a white space character " ", but it is actually a "\n" character. Could you check that? Just replace the " " for "\n". – Alexandre Justino Jun 10 '14 at 05:27
-1

try to implode and explode with a separated something like ;

    $temp_string = implode(";", $temp_array_links); //convert array to string
    $info_array_links = explode(";", $temp_string); //explode string
ashok_p
  • 741
  • 3
  • 8
  • 17