Php 带有'&引用;计数为两个字符

Php 带有'&引用;计数为两个字符,php,wordpress,serialization,Php,Wordpress,Serialization,我在php序列化方面遇到了问题,当包含“.”时,我会得到一个额外的字符空间。例如,如果是6个字符,我会得到7个 $episodes_count = sizeof($episode_title); $episodes = array(); $content = ''; for ($i = 0; $i <= $episodes_count; $i++) { $title = htmlspecialchars($episode_title[$i], ENT_QUOTES);

我在php序列化方面遇到了问题,当包含“.”时,我会得到一个额外的字符空间。例如,如果是6个字符,我会得到7个

   $episodes_count = sizeof($episode_title);
$episodes = array();
$content = '';

for ($i = 0; $i <= $episodes_count; $i++) {
    $title = htmlspecialchars($episode_title[$i], ENT_QUOTES);
    $airdate    = $episodes_airdates[$i];
    $season    = $episodes_seasons[$i];
    $number    = $episodes_numbers[$i];
    $plot    = $episodes_plot[$i];

    // check if empty
    if (!empty($title) && !empty($number ) && !empty($plot )) {
        $episodes[] = array(
            'title' => $title, 
            'airdate' => $airdate,
            'season' => $season,
            'number'   => $number,
            'plot'   => $plot,
        );
    }
}

// Serialized Episodes in case they exist, if not, remove the goal post
if ( sizeof($episodes) > 0 ) {
    $content = str_replace("'", '%',serialize($episodes));
}


update_post_meta($post_id, 'episodes', $content);
}
$scents\u count=sizeof($scents\u title);
$scents=array();
$content='';
对于($i=0;$i$标题,
“airdate”=>$airdate,
“季节”=>$季节,
“number”=>$number,
“绘图”=>$plot,
);
}
}
//如果存在序列化的剧集,则删除目标帖子
如果(sizeof($集)>0){
$content=str_replace(“'”,“%”,序列化($scents));
}
更新发布元($post\u id,$seconds',$content);
}

您将一些看起来已序列化的数据传递给wordpress,以
更新\u post\u meta
-wordpress可能会遇到此问题,并且在存储和检索时数据会被破坏


为了防止出现这种情况,您可以为字符串添加前缀,使其看起来不再序列化,甚至可以对整个字符串进行编码,例如使用。这将防止wordpress和其他组件由于编码问题修改值。

人们使用
sizeof()
?:)那么,您只是想修剪多余的空白或从标题中转义单引号和双引号吗?不要期望wordpress将您的序列化字符串处理为未序列化。Post Meta会自动序列化,这可能会发生,也可能不会发生,当再次读入时,它将被评为序列化,但因为您更改了字符串,它将被破坏。@MetalFrog是的,我使用sizeof(),哈哈。为了回答你的另一个问题,我试图消除空白。@hakre我不太清楚你的意思?我并不是真的依靠WordPress来处理序列化数据。@Craig:但你在这里做:
update\u post\u meta
这应该作为WordPress中的一个bug提交。@EmilVikström:这已经被报道过了,但是没有不同意修复它,因为它实际上是设计的。