Skip to content

Instantly share code, notes, and snippets.

@VasylKyryliuk
Created February 21, 2018 13:29
Show Gist options
  • Save VasylKyryliuk/90f1ac27aafe6d5f75ff885b2dd4b629 to your computer and use it in GitHub Desktop.
Save VasylKyryliuk/90f1ac27aafe6d5f75ff885b2dd4b629 to your computer and use it in GitHub Desktop.
SELECT BSMU
<?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) => '&euro;',
chr(0x82) => '&sbquo;',
chr(0x84) => '&bdquo;',
chr(0x85) => '&hellip;',
chr(0x86) => '&dagger;',
chr(0x87) => '&Dagger;',
chr(0x89) => '&permil;',
chr(0x8B) => '&lsaquo;',
chr(0x91) => '&lsquo;',
chr(0x92) => '&rsquo;',
chr(0x93) => '&ldquo;',
chr(0x94) => '&rdquo;',
chr(0x95) => '&bull;',
chr(0x96) => '&ndash;',
chr(0x97) => '&mdash;',
chr(0x99) => '&trade;',
chr(0x9B) => '&rsquo;',
chr(0xA6) => '&brvbar;',
chr(0xA9) => '&copy;',
chr(0xAB) => '&laquo;',
chr(0xAE) => '&reg;',
chr(0xB1) => '&plusmn;',
chr(0xB5) => '&micro;',
chr(0xB6) => '&para;',
chr(0xB7) => '&middot;',
chr(0xBB) => '&raquo;',
);
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