- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在开发一个具有两个主要功能的 WordPress 网站/博客。
人们可以编写报告,选择他们需要的字段并发布。然后在一天结束时,他们可以从所有报告中“编译”一份最终报告(它连接所有报告的字段)。
主题是二十个(如果它可能有用的话)。
在我的 function.php 文件中,我使用 foreach 和类似的行连接最终报告的所有内容:
$Urgences_Environnementales .= htmlspecialchars("<br/>".get_field('Urgences_Environnementales', $idnumber->ID));
$avezvous_regardé_des_indices_de_temps_violent_aujourdhui .= htmlspecialchars(get_field('avezvous_regardé_des_indices_de_temps_violent_aujourdhui', $idnumber->ID));
$quelle_est_cette_raison .= htmlspecialchars(get_field('quelle_est_cette_raison', $idnumber->ID));
每个字段一行,都是一样的。循环完成后,我更新字段:
update_field('Urgences_Environnementales',preg_replace('/(<br[\s]?[\/]?>[\s]*){2,}/', '<br/><br/>', htmlspecialchars_decode($Urgences_Environnementales)), $identificationRapport);
update_field('avezvous_regardé_des_indices_de_temps_violent_aujourdhui',preg_replace('/(<br[\s]?[\/]?>[\s]*){2,}/', '<br/><br/>', htmlspecialchars_decode($avezvous_regardé_des_indices_de_temps_violent_aujourdhui)), $identificationRapport);
update_field('quelle_est_cette_raison',preg_replace('/(<br[\s]?[\/]?>[\s]*){2,}/', '<br/><br/>', htmlspecialchars_decode($quelle_est_cette_raison)), $identificationRapport);
然后像这样打印最终报告(这是一个字段):
if(strip_tags(html_entity_decode(get_field('Urgences_Environnementales')))!=''){
simplebox(strip_tags(html_entity_decode(get_field('Urgences_Environnementales')))!='', get_field('Urgences_Environnementales'));
}
对于那些领域,它工作得很好。
我的问题是我的所有由数组组成的字段(人们可以使用 ACF 插件选择多个选项的复选框)在我的数据库中都是空的...它们在单个报告中完美显示,但是它们在最终报告中显示为空白。
例如,这是我在数据库中看到的一个数组的单个报告:
a:4:{i:0;s:49:"L’indice d’intensité d’orage violent (STI)";i:1;s:35:"L’indice d’orage violent (TMPV)";i:2;s:34:"Potential Severe Storm Environment";i:3;s:6:"Autres";}
我的最终报告中相应的字段是空的。
有人知道如何读取这些数组并将它们正确记录在我的数据库中吗?我可以在 foreach 循环中将它们转换为字符串吗?我应该做些不同的事情吗?
如果您需要更多代码,请随时询问。我没有将所有 3 个函数(functions.php、report.php、finalreport.php)放入我的 WordPress 主题中因为它需要很多行,我很确定最重要的就在这里。如果我错了,我可以发布函数。
我找了又找,但我自己似乎找不到答案,所以我在这里寻求帮助。
PS:这是我的第一篇文章,如果大家有什么建议可以发给我,我会改的。
非常感谢您的帮助!
PPS:我很抱歉我的英语不好,我是法国人,来自加拿大魁北克省蒙特利尔。
最佳答案
高级自定义字段将一些值存储为序列化数组(复选框、重复器等)。您的代码假设您将得到一个字符串。正如您在回答中所建议的那样,在当前代码中解决这个问题的最简单方法是使用 is_array()
方法检查返回值的类型,然后使用另一个内部循环来处理摘要。此代码假设您只想连接所有值,您可以轻松地使用另一个数组来确保它们是唯一的,等等。
// get the value from acf
$value = get_field( 'Urgences_Environnementales', $idnumber->ID );
// if it's already an array, use that, if not make it into an array with a single element
$value_arr = ( is_array( $value ) )? $value : array( $value );
$text = ""; // reset since this is in a loop
// concatenate each checkbox value
foreach ( $value_arr as $val ){
$text .= $val . ', ';
}
// append it to the main summary
$Urgences_Environnementales .= htmlspecialchars( "<br/>". $text );
关于php - WordPress PHP htmlspecialchars(get_field... 无法读取数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24748595/
我的问题类似于this问题,但我没有使用代码点火器。我将从数据库获得的变量回显到文本输入的值属性中。变量可能包含 ' 或 "或任何其他特殊字符。 我试过: " /> 但它将引号输出为 " 或 ' 这不
我在 mysql 字段中有如下的外观, Hello there world 当我使用这段代码格式化上面的内容时: echo htmlspecialchars($thestring) 它输出这个,
我遇到了一个特定的字符串(它不是完全可打印的,但您可以在下面看到它)导致 htmlspecialchars() 返回零长度字符串。有什么办法可以解决这个问题吗? $Stmnt = 'SELECT su
我正在从以下 php 代码生成链接。链接出现在浏览器中,生成的 html 代码看起来不错,但是链接不可点击。我已经在 IE 和 FF 中对此进行了测试,并尝试使用 FireBug 查看无济于事。 生成
我使用 phpMyDataGird 脚本通过网络编辑 MySQL 数据库表,而不使用 phpMyAdmin(我只是使用 phpMyAdmin 来管理值,但这个脚本来管理数据) 当我将 HTML 添加到
input.replace("&", "&").replace("<", "").replace(""", "\""); 我将这行代码用作 sudo htmlspecialch
这个问题在这里已经有了答案: How can I prevent SQL injection in PHP? (27 个答案) 关闭 6 年前。 我的代码是: $description = $_PO
大家好,查看了 php 文档并四处搜索,但没有任何乐趣。这是我的代码片段,htmlspecialchars 似乎不起作用,用错了吗? $query="SELECT * FROM likes"; $re
我获取 $_POST 信息并将其存储在数据库中,稍后查询并将此信息打印给用户。我应该在插入此信息之前使用 htmlspecialchars() 还是在查询它之后再输出它? 此外,我需要让用户能够使用引
我正在尝试使用 htmlspecialchars 但它似乎不起作用。我正在使用 OSX 10.9.1 和 PHP 5.4.17。我写: var_dump(htmlspecialchars("Test"
__('Details & Documents') ?> 上面的打印输出为:Details &文档 什么是正确的语法才能打印为:Details & Documents? 谢谢 最佳答案 html_en
很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visit the help center . 关闭 1
这个问题在这里已经有了答案: when to use htmlspecialchars() function? (4 个答案) 关闭 9 年前。 我需要使用以下方法将我的字符串转换为特殊字符: h
为什么会这样 $trader_details = array_walk($trader_details, 'htmlspecialchars'); 给这个错误? Severity: Warning M
我正在为我的老板构建一个 PHP 内联网。一个简单的客户、订单、报价系统。它将被拒绝从 Internet 访问,并且只能由 3 人使用。我不太关心安全性,因为我关心验证。 Javascript 在所有
同时使用 htmlspecialchars 和 htmlentities 会导致 ™ 符号甚至单个 ' 引号等项出现空白输出。显然,这绝对是无用的,但是在不使用 html 字符的情况下输出数据会导致这
这似乎是一个简单的问题,但我在文件中找不到它。 如何扭转 htmlspecialchars 的影响? 我试过这样的: $trans_tbl = get_html_translation_table (
如何在数组对象数组上运行 PHP 函数 htmlspecialchars()? 我有以下代码: $result_set = Array ( [0] => Array (
1、html_entity_decode():把html实体转换为字符。 ?
PHP htmlspecialchars() 函数 实例 把预定义的字符 "<" (小于)和 ">" (大于)转换为 HTML 实体:
我是一名优秀的程序员,十分优秀!