1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
| <?php
header("Content-type:text/plain");
$conn = new mysqli("localhost", "root", "1234", "wordpress");
$conn->set_charset("utf8");
$result = $conn->query("SELECT post_content, ID FROM wp_posts");
$stmt = $conn->prepare("UPDATE wp_posts SET post_content = ? WHERE ID = ?");
$search = array();
$replace = array();
$reparr = array(
'[py]' => '【crayon lang="python"]',
'[cpp]' => '【crayon lang="cpp"]',
'[pas]' => '【crayon lang="pascal"]',
'[php]' => '【crayon lang="php"]',
'[html]' => '【crayon lang="html"]',
'[/py]' => '【/crayon]'
'[/cpp]' => '【/crayon]',
'[/pas]' => '【/crayon]',
'[/php]' => '【/crayon]',
'[/html]' => '【/crayon]',
);
$count = 0;
foreach ($reparr as $key => $value)
{
$search[$count] = $key;
$replace[$count] = $value;
++$count;
}
while ($row = $result->fetch_array())
{
$id = $row['ID'];
$post_content = str_replace($search, $replace, $row['post_content']);
$stmt->bind_param('si', $post_content, $id);
if (!$stmt->execute())
{
die("n[ERROR!]".$id."n");
}
else
{
echo "[Success]".$id."n";
}
}
$result->free();
$conn->close();
?>
|