【问题标题】:explode() doesn't work on get_the_author_meta('description');explode() 对 get_the_author_meta('description') 不起作用;
【发布时间】:2016-07-29 09:30:03
【问题描述】:

我正在使用get_the_author_meta('description') 函数通过以下代码在 WordPress 中获取作者描述:

$author_desc = get_the_author_meta('description');
$author_data = explode('>', $author_desc);
var_dump($author_data);

描述为:E-commerce consultant>man>het e-commerce。我希望explode函数创建3个数组项,用'>'分割字符串。

但是结果是这样的:

array (size=1)
  0 => string 'E-commerce consultant>man>het e-commerce' (length=46)

似乎它确实将字符串放入了一个数组中,但只创建了一行...

【问题讨论】:

  • 也许用str_replace将>替换成另一组字符,比如
    ,然后用
    展开。

标签: php arrays wordpress explode


【解决方案1】:

而不是> char 有实体>。你可以通过这个实体字符串来爆炸:

$author_desc = get_the_author_meta('description');
$author_data = explode('>', $author_desc); // explode by > instead of >
var_dump($author_data);

Fiddle

【讨论】:

  • 不是也许,肯定是这样的:)
猜你喜欢
  • 1970-01-01
  • 2013-05-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-03-22
  • 1970-01-01
  • 1970-01-01
  • 2019-09-07
相关资源
最近更新 更多