wordpress转存json数据

wordpress admin 278℃ 0评论

PYTHON存入json文件数据,文章内容保存为对应的文件

# -*- coding: utf-8 -*-

import json
import sys
reload(sys)
sys.setdefaultencoding("utf-8")

html = '';
with open('source.txt') as f:
    html = f.read()

post = {
    'title': 'test title',
}

json_str = json.dumps(post)

with open('test.json', 'w') as f:
    f.write(json_str)


json_str = ''
with open('test.json') as f:
    json_str = f.read()

json_data = json.loads(json_str)

print json_data

 

PHP转存入mysql数据库

<?php
header("Content-Type: text/html; charset=utf-8");
$con=mysqli_connect("localhost","root","","wordpress"); 
if (mysqli_connect_errno($con)) 
{ 
    echo "连接 MySQL 失败: " . mysqli_connect_error(); 
} 

$dir = 'json';
$dirArr = scandir($dir);
foreach($dirArr as $v){
    if($v!='.' && $v!='..'){
        $dirname = $dir.'\\'.$v;  

        $json_data = file_get_contents($dirname);
        $data = json_decode($json_data, true);
        print_r($data['title']);
    }
}

$sql="SELECT * FROM wp_post";
$result=mysqli_query($con,$sql);
 
$row=mysqli_fetch_array($result,MYSQLI_ASSOC);
printf ("%s : %s",$row["post_title"],$row["post_content"]);
 
mysqli_free_result($result);
 
mysqli_close($con);

 

转载请注明:朋克网 » wordpress转存json数据

喜欢 (0)
发表我的评论
取消评论
表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址