我一直在试图找出如何从短代码属性中转义引号(单引号和双引号)。
基本上,内容是由用户编写的,因此可能会包含“and”引号。问题是,使用“引号”会阻止shortcode属性的功能,例如:
attibute=“此处的一些文本带有“引号”,因此它会停止属性…”
因此,它不是获取整个字符串,而是在第二对引号处停止。
现在,我知道可以使用单引号进行设置,但如果用户在文本中使用单引号,则会留下同样的困境。
我已经研究了各种PHP/WP解决方案,但我似乎无法让它们中的任何一个正常工作,例如esc\\U html、htmlspecialchars、htmlentities。
可能是我设置错误,或者没有在正确的位置执行编码。
这是我目前使用的(无编码)短码(略短)
function aps_person_schema_shortcode( $atts, $content = null) {
extract( shortcode_atts( array(
\'aps_person_description\' => \'\'
), $atts
)
);
$aps_person_return = \'<div class="aps_person_container aps_container">\';
$aps_person_return .= \'<p class="aps_person_description" itemprop="description">\' . $aps_person_description . \'</p>\';
$aps_person_return .= \'</div>\';
return $aps_person_return;
}
add_shortcode(\'aps_person\', \'aps_person_schema_shortcode\');
我尝试在提取数组之后添加$aps_person_description = esc_html($atts[\'aps_person_description\']);
但由于属性已经损坏(print\\r显示引号后的字符串被分隔为每个单词的数组项),因此转义字符串不起作用。在数组之前尝试过它,但它也不起作用。我收到一个通知:未定义索引
那么,为了澄清,您如何清理用户输入的短代码属性数据?