我有一个名为$allFeeds
的关联数组(在执行print_r($allFeeds);
之后),如下所示:
Array
(
[0] => Array
(
[feed_status] => Vividly dug<br />Hchxhh civic<br />Hchxhh cuffing<br />Viccydyduiggigig<br />Bivucfigigudufyd<br />Chchcfhdhcjcfufhcjvjgjfhg<br />Jfufjfufigijdgdjcj<br />Crucify fix<br />Ogives gif<br />Gucucvi<br />Jfufjfufigijdgdjcj<br />Juicy fiduciary<br />Chchcfhdhcjcfufhcjvjgjfhg<br />Jcjcufufydxy<br />Igufucuducufuf<br />Jxjdfjdjdj<br />Vuycychxxhgx<br />Ibis figjfhdjhljgh<br />Chchcfhdhcjcfufhcjvjgjfhg<br />Jfufjfufigijdgdjcj<br />Hchxhh chic<br />Jfufjfufigijdgdjcj<br />Hchxchcfzdhfjhgjvjvh<br />Chchcfhdhcjcfufhcjvjgjfhg<br />Hchxhh chic<br />Huhxxgxgxhxjchxhcjhkkbj<br />Hchxhh dhfjgjigk<br />Huffy djcdxjbghc<br />Hchxgxxgxhgxgc<br />Chchcfhdhcjcfufhcjvjgjfhg<br />Chchcfhdhcjcfufhcjvjgjfhg<br />Hchxhh sha<br />Jhchxhxhchcfchjc<br />Jccchcydfydfy<br />Chchcfhdhcjcfufhcjvjgjfhg<br />Huhxyfgchdjc<br />Jcfhfjfjjf<br />Jcfhfjfjjf
)
[1] => Array
(
[feed_status] => Prodded<br />Fuzhou<br />Chchcfhdhcjcfufhcjvjgjfhg<br />Off finish<br />Hogfish I<br />Ifusudigogig<br />Jfufjfufigijdgdjcj<br />Hxhxhfjfufjf<br />It's sufficed<br />Hchxhh<br />Hdufjkvhchcfudgfycjufhkjgh<br />
)
[2] => Array
(
[feed_status] => Jfkfzzogzgi<br />Jffixgoogxgox<br />Kfcjjfgk soffits<br />Dufhfkgk gaits<br />Yahoo googles<br />Kxgzgxgohbjhgfbhjvfdhhcdbkjh<br />
)
)
现在,我想从上面的每个值中将<br />
替换为\n
。为此,我写了以下常见功能:
function br2nl($buff = '') {
$buff = mb_convert_encoding($buff, 'HTML-ENTITIES', "UTF-8");
$buff = preg_replace('#<br[/\s]*>#si', "\n", $buff);
$buff = trim($buff);
return $buff;
}
现在使用此功能,我已编写以下代码:
$cnt = 0;
foreach ($allFeeds as $key => $value) {
$allFeeds[$cnt]['feed_status'] = br2nl($value['feed_status']);
$cnt++;
}
现在,如果我print_r($allFeeds);
我得到了结果:
Array
(
[0] => Array
(
[feed_status] =>
)
[1] => Array
(
[feed_status] =>
)
[2] => Array
(
[feed_status] =>
)
)
我不明白为什么会这样。有人可以在这个问题上帮助我吗?
预期产出如下:
Array
(
[0] => Array
(
[feed_status] => Vividly dug\nHchxhh civic\nHchxhh cuffing\nViccydyduiggigig\nBivucfigigudufyd\nChchcfhdhcjcfufhcjvjgjfhg\nJfufjfufigijdgdjcj\nCrucify fix\nOgives gif\nGucucvi\nJfufjfufigijdgdjcj\nJuicy fiduciary\nChchcfhdhcjcfufhcjvjgjfhg\nJcjcufufydxy\nIgufucuducufuf\nJxjdfjdjdj\nVuycychxxhgx\nIbis figjfhdjhljgh\nChchcfhdhcjcfufhcjvjgjfhg\nJfufjfufigijdgdjcj\nHchxhh chic\nJfufjfufigijdgdjcj\nHchxchcfzdhfjhgjvjvh\nChchcfhdhcjcfufhcjvjgjfhg\nHchxhh chic\nHuhxxgxgxhxjchxhcjhkkbj\nHchxhh dhfjgjigk\nHuffy djcdxjbghc\nHchxgxxgxhgxgc\nChchcfhdhcjcfufhcjvjgjfhg\nChchcfhdhcjcfufhcjvjgjfhg\nHchxhh sha\nJhchxhxhchcfchjc\nJccchcydfydfy\nChchcfhdhcjcfufhcjvjgjfhg\nHuhxyfgchdjc\nJcfhfjfjjf\nJcfhfjfjjf
)
[1] => Array
(
[feed_status] => Prodded\nFuzhou\nChchcfhdhcjcfufhcjvjgjfhg\nOff finish\nHogfish I\nIfusudigogig\nJfufjfufigijdgdjcj\nHxhxhfjfufjf\nIt's sufficed\nHchxhh\nHdufjkvhchcfudgfycjufhkjgh\n
)
[2] => Array
(
[feed_status] => Jfkfzzogzgi\nJffixgoogxgox\nKfcjjfgk soffits\nDufhfkgk gaits\nYahoo googles\nKxgzgxgohbjhgfbhjvfdhhcdbkjh\n
)
)
答案 0 :(得分:2)
在for循环中,使用
@Test
public void testEntityName() {
PageDataModel pageDataModel = new PageDataModel("testing");
pageDataModel.setContents("person");
String temp = pageDataModel.getContents();
assertEquals("person",temp );
}
而不是
$allFeeds[$cnt]['feed_status'] = br2nl($allFeeds[$cnt]['feed_status']);