Created
February 21, 2018 13:29
-
-
Save VasylKyryliuk/90f1ac27aafe6d5f75ff885b2dd4b629 to your computer and use it in GitHub Desktop.
SELECT BSMU
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$servername = "localhost"; | |
$username = "root"; | |
$password = "root"; | |
$dbname = "bsmu"; | |
// Create connection | |
$conn = new mysqli($servername, $username, $password, $dbname); | |
// Check connection | |
if ($conn->connect_error) { | |
die("Connection failed: " . $conn->connect_error); | |
} | |
$args = array( | |
'post_status' => 'publish', | |
'posts_per_page' => 2000, | |
); | |
$posts = $wp_query->query($args); | |
function w1250_to_utf8($text) { | |
// map based on: | |
$map = array( | |
chr(0x8A) => chr(0xA9), | |
chr(0x8C) => chr(0xA6), | |
chr(0x8D) => chr(0xAB), | |
chr(0x8E) => chr(0xAE), | |
chr(0x8F) => chr(0xAC), | |
chr(0x9C) => chr(0xB6), | |
chr(0x9D) => chr(0xBB), | |
chr(0xA1) => chr(0xB7), | |
chr(0xA5) => chr(0xA1), | |
chr(0xBC) => chr(0xA5), | |
chr(0x9F) => chr(0xBC), | |
chr(0xB9) => chr(0xB1), | |
chr(0x9A) => chr(0xB9), | |
chr(0xBE) => chr(0xB5), | |
chr(0x9E) => chr(0xBE), | |
chr(0x80) => '€', | |
chr(0x82) => '‚', | |
chr(0x84) => '„', | |
chr(0x85) => '…', | |
chr(0x86) => '†', | |
chr(0x87) => '‡', | |
chr(0x89) => '‰', | |
chr(0x8B) => '‹', | |
chr(0x91) => '‘', | |
chr(0x92) => '’', | |
chr(0x93) => '“', | |
chr(0x94) => '”', | |
chr(0x95) => '•', | |
chr(0x96) => '–', | |
chr(0x97) => '—', | |
chr(0x99) => '™', | |
chr(0x9B) => '’', | |
chr(0xA6) => '¦', | |
chr(0xA9) => '©', | |
chr(0xAB) => '«', | |
chr(0xAE) => '®', | |
chr(0xB1) => '±', | |
chr(0xB5) => 'µ', | |
chr(0xB6) => '¶', | |
chr(0xB7) => '·', | |
chr(0xBB) => '»', | |
); | |
return html_entity_decode(mb_convert_encoding(strtr($text, $map), 'UTF-8', 'ISO-8859-2'), ENT_QUOTES, 'UTF-8'); | |
} | |
foreach ($posts as $post) { | |
setup_postdata($post); | |
if (get_post_meta(get_the_ID(), '_fgj2wp_old_k2_id', true)) { | |
$sql = "SELECT id, alias FROM bsmuw1_k2_items WHERE id = ".get_post_meta(get_the_ID(), '_fgj2wp_old_k2_id', true).";"; | |
$result = $conn->query($sql); | |
if ($result->num_rows > 0) { | |
while ($row = $result->fetch_assoc()) { | |
//$row["alias"] = mb_convert_encoding($row["alias"], "UTF-8"); | |
//$row["alias"] = iconv('ASCII', 'UTF-8//IGNORE', $row["alias"]); | |
//echo mb_detect_encoding( $row["alias"] ); | |
echo "Redirect 301 /uk/(.*)/" . $row["id"] . "-" . w1250_to_utf8($row["alias"]) . " "; | |
echo get_the_permalink(); | |
} | |
} | |
echo "\n"; | |
} | |
} | |
$conn->close(); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment