我必须映射一个 xml 文件并将其节点插入到 wordpress mysql 表中
$postTable = $wpdb->prefix . "posts";
$nouvelles = simplexml_load_file('annonces.xml');
foreach($nouvelles->ANNONCE as $annonce) {
$wpdb->insert(
$postTable, $post_arr =array(
'post_author' => 1,
'post_date' => current_time('mysql', 1) ,
'post_date_gmt'=>current_time('mysql', 1),
'post_content' =>utf8_decode($annonce->TEXTE),
'post_title'=>utf8_decode($annonce->TITRE),
'post_excerpt'=>'',
'post_status'=>'publish',
'comment_status'=>'closed',
'ping_status'=>'closed',
'post_password'=>'',
'post_name'=>str_replace(' ','-',utf8_decode($annonce->TITRE)),
'to_ping'=>'',
'pinged'=>'',
'post_modified'=>date("M d Y H:i:s"),
'post_modified_gmt'=>gmdate("M d Y H:i:s"),
'post_content_filtered'=>'',
'post_parent'=>0,
'guid'=>Site_url().'?post_type=property&p='.$idPost,
'menu_order'=>0,
'post_type'=>'property',
'post_mime_type'=>'',
'comment_count'=>''
));
}
我的文本节点在 annonce.xml 中,如下所示:
<TEXTE>PAVILLON TRADITIONNEL EDIFIE SUR SOUS SOL TOTAL !! Vaste salon sejour avec cheminee, grande cuisine amenagee et equipee donnant sur une veranda, 4 chambres, piscine chauffee, PRESTATIONS DE QUALITES</TEXTE>
仅在 mysql posts 表中
"PAVILLON TRADITIONNEL EDIFIE SUR SOUS SOL TOTAL !! Vaste salon s"
插入到'post_content'字段中,我还有两个'ANNONCE'节点。 是否是缓冲区溢出?
PS:'post_content'字段类型为longtext,我尝试在第一次迭代中退出循环,该字段已完全插入,我尝试增加memory_limit,将output_buffering更改为on。
最佳答案
这是utf8_decode的问题,我删除了它,问题解决了。
关于php - 插入mysql不完整值字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23884979/