Guest User

Untitled

a guest
Mar 3rd, 2018
278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.67 KB | None | 0 0
  1. <?php
  2.  
  3. $servername = "localhost";
  4. $username = "root";
  5. $password = "root";
  6. $dbname = "bsmu";
  7.  
  8. // Create connection
  9. $conn = new mysqli($servername, $username, $password, $dbname);
  10. // Check connection
  11. if ($conn->connect_error) {
  12. die("Connection failed: " . $conn->connect_error);
  13. }
  14.  
  15.  
  16. $args = array(
  17. 'post_status' => 'publish',
  18. 'posts_per_page' => 2000,
  19. );
  20. $posts = $wp_query->query($args);
  21.  
  22. function w1250_to_utf8($text) {
  23. // map based on:
  24. $map = array(
  25. chr(0x8A) => chr(0xA9),
  26. chr(0x8C) => chr(0xA6),
  27. chr(0x8D) => chr(0xAB),
  28. chr(0x8E) => chr(0xAE),
  29. chr(0x8F) => chr(0xAC),
  30. chr(0x9C) => chr(0xB6),
  31. chr(0x9D) => chr(0xBB),
  32. chr(0xA1) => chr(0xB7),
  33. chr(0xA5) => chr(0xA1),
  34. chr(0xBC) => chr(0xA5),
  35. chr(0x9F) => chr(0xBC),
  36. chr(0xB9) => chr(0xB1),
  37. chr(0x9A) => chr(0xB9),
  38. chr(0xBE) => chr(0xB5),
  39. chr(0x9E) => chr(0xBE),
  40. chr(0x80) => '&euro;',
  41. chr(0x82) => '&sbquo;',
  42. chr(0x84) => '&bdquo;',
  43. chr(0x85) => '&hellip;',
  44. chr(0x86) => '&dagger;',
  45. chr(0x87) => '&Dagger;',
  46. chr(0x89) => '&permil;',
  47. chr(0x8B) => '&lsaquo;',
  48. chr(0x91) => '&lsquo;',
  49. chr(0x92) => '&rsquo;',
  50. chr(0x93) => '&ldquo;',
  51. chr(0x94) => '&rdquo;',
  52. chr(0x95) => '&bull;',
  53. chr(0x96) => '&ndash;',
  54. chr(0x97) => '&mdash;',
  55. chr(0x99) => '&trade;',
  56. chr(0x9B) => '&rsquo;',
  57. chr(0xA6) => '&brvbar;',
  58. chr(0xA9) => '&copy;',
  59. chr(0xAB) => '&laquo;',
  60. chr(0xAE) => '&reg;',
  61. chr(0xB1) => '&plusmn;',
  62. chr(0xB5) => '&micro;',
  63. chr(0xB6) => '&para;',
  64. chr(0xB7) => '&middot;',
  65. chr(0xBB) => '&raquo;',
  66. );
  67. return html_entity_decode(mb_convert_encoding(strtr($text, $map), 'UTF-8', 'ISO-8859-2'), ENT_QUOTES, 'UTF-8');
  68. }
  69.  
  70. foreach ($posts as $post) {
  71. setup_postdata($post);
  72. if (get_post_meta(get_the_ID(), '_fgj2wp_old_k2_id', true)) {
  73.  
  74.  
  75. $sql = "SELECT id, alias FROM bsmuw1_k2_items WHERE id = ".get_post_meta(get_the_ID(), '_fgj2wp_old_k2_id', true).";";
  76. $result = $conn->query($sql);
  77.  
  78. if ($result->num_rows > 0) {
  79. while ($row = $result->fetch_assoc()) {
  80.  
  81. //$row["alias"] = mb_convert_encoding($row["alias"], "UTF-8");
  82. //$row["alias"] = iconv('ASCII', 'UTF-8//IGNORE', $row["alias"]);
  83.  
  84. //echo mb_detect_encoding( $row["alias"] );
  85. echo "Redirect 301 /uk/(.*)/" . $row["id"] . "-" . w1250_to_utf8($row["alias"]) . " ";
  86. echo get_the_permalink();
  87.  
  88.  
  89. }
  90. }
  91.  
  92. echo "\n";
  93. }
  94. }
  95.  
  96. $conn->close();
  97.  
  98. ?>
Add Comment
Please, Sign In to add comment