array_map和htmlentities [英] array_map and htmlentities

查看:92
本文介绍了array_map和htmlentities的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试使用array_map通过htmlentities() 将字符转换为HTML实体,如下所示:

I've been trying using array_map to convert characters to HTML entities with htmlentities() like this:

$lang = array_map('htmlentities', $lang);

我的数组如下:

$lang = array();
$lang['var_char1']['varchar2'] = 'Some Text';

但我不断收到此错误:

警告:htmlentities()期望参数1为字符串,给定数组 在第1335行的/home/user/public_html/foo/lang/en.inc.php中

Warning: htmlentities() expects parameter 1 to be string, array given in /home/user/public_html/foo/lang/en.inc.php on line 1335

有人知道这可能是什么问题吗?谢谢!

Does anyone know what could be the problem? Thank you!

推荐答案

因为$ lang是一个二维数组,所以它不起作用

Because $lang is a two dimensional array, so it won't work

对于二维数组,您需要使用for循环

For two dimensional array you need to use for loop

foreach($$lang as &$l):
    $l = array_map('htmlentities', $l);
}

这篇关于array_map和htmlentities的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆