将 &#038 转换回 &#038 [英] Convert &#038 back to ampersand

查看:29
本文介绍了将 &#038 转换回 &#038的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 wordpress,并且对于我正在处理的网站,我已经设置了一个自定义帖子类型来列出他们的每项服务和详细信息.

I'm using wordpress, and for the website that I'm working on, I've set up a custom post type for listing each of their services and details.

在他们的自定义联系表单上,我查询自定义帖子类型以将每个帖子的标题放入选项列表中,以便用户可以选择他们感兴趣的服务.

On their custom contact form, I'm querying the custom post type to get the titles for each post into an option list so a user can select which service they're interested in.

提交表单时,表单逻辑的一部分检查是否填写了所有必填字段,如果没有,它会发出警报并要求用户填写所需信息.

Part of the form logic when the form is submitted checks to see that all of the required fields are filled in, and if not, it gives an alert and asks the user to fill in the needed info.

我在每个输入中有一段 php 代码,用于将发布的数据回显到表单中,这样它就不会丢失,我正在尝试对下拉选项执行相同的操作,但我遇到了非常令人沮丧的问题:

I have a piece of php code in each input to echo the posted data back into the form so that it is not lost, and I'm trying to do the same for the option drop down but I'm running into a really frustrating issue:

任何带有与号的 wordpress 帖子标题都会将与号替换为 &#038 的字符代码,这很好,它显示为 &在我的浏览器中,但提交后它变成了 &在帖子数据中.

Any wordpress post title with and ampersand in it is having the ampersand replaced by a char code of &#038, which is fine, it shows as an & in my browser, but after it's submitted it turns into an & in the post data.

当我尝试将每个帖子标题与提交的选择进行比较时,if 语句从未找到匹配项,因为 &#038 和 &不匹配.

When I try to compare each post title to the submitted selection, the if statement never finds a match because the &#038 and & don't match up.

我尝试在 wordpress 的标题上使用 htmlspecialchars_decode(),但这并没有将 &#038 解码回 &.

I've tried using htmlspecialchars_decode() on the titles from wordpress, but this doesn't decode the &#038 back into and &.

有没有人知道一个函数来完成这个并解码可能弹出的任何奇怪的字符编码?

Does anyone know of a function to accomplish this and decode any weird char encoding that might pop up?

这是发生这种情况的 while 循环.

Here's my while loop where this takes place.

while ($custom_post_type->have_posts()) : $custom_post_type->the_post();

//set selected if submission is bouncing back                                       
if($_POST['ftype'] == get_the_title())
{
    $the_selected = ' selected="selected" ';
}
else
{
    $the_selected = '';
}

?>

    <option value="<?php echo get_the_title(); ?>" <?php echo $the_selected; ?>><?php echo get_the_title(); ?></option>

<?php


endwhile;

推荐答案

html_entity_decode 应该可以工作.

echo html_entity_decode('&#038;');

这篇关于将 &amp;#038 转换回 &amp;#038的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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