【问题标题】:Explode an longtext into array将长文本分解成数组
【发布时间】:2014-06-10 05:15:31
【问题描述】:

我在 mysql db 中有 longtext 列,并希望将其扩展为数组。但是 explode 只返回 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/    

【问题讨论】:

标签: php arrays explode implode


【解决方案1】:

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

【讨论】:

  • 哦,实验后留下的,抱歉,问题没有解决
  • 有时它会打印一个空白字符“”,但它实际上是一个“\n”字符。你能检查一下吗?只需将“”替换为“\n”即可。
【解决方案2】:

你的$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

【讨论】:

  • 试试 print_r($temp_array_links) 并显示你的结果
【解决方案3】:

尝试用像 ; 之类的分隔符来内爆和爆炸

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

【讨论】:

  • 你检查过你在 implode 后得到的字符串是什么吗?
  • 我认为是变量名的问题
猜你喜欢
  • 2021-09-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-08-15
  • 2015-07-26
  • 2019-06-02
  • 2022-11-16
相关资源
最近更新 更多