Guest User

Untitled

a guest
Mar 20th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. <?php
  2. $con=mysqli_connect("localhost","user","senha","banco");
  3. $parametro = $_GET["parametro"];
  4. if (mysqli_connect_errno()){ echo "Failed to connect to MySQL: " .mysqli_connect_error(); }
  5. $sql = "SELECT * FROM " . $parametro;
  6.  
  7. if ($result = mysqli_query($con, $sql))
  8. {
  9. $resultArray = array();
  10. $tempArray = array();
  11.  
  12. while($row = $result->fetch_object())
  13. {
  14. $tempArray = $row;
  15. array_push($resultArray, $tempArray);
  16. }
  17. echo json_encode($resultArray);
  18. }
  19. mysqli_close($con);
  20. ?>
  21.  
  22. $str = str_replace('u','u',$decoded);
  23. $strJSON = preg_replace('/u([da-fA-F]{4})/', '&#x1;', $str);
  24.  
  25. echo json_encode($json, JSON_UNESCAPED_UNICODE);
  26.  
  27. echo json_encode($json);
  28.  
  29. <?php
  30. $con=mysqli_connect("localhost","user","senha","banco");
  31. $parametro = $_GET["parametro"];
  32. if (mysqli_connect_errno()){ echo "Failed to connect to MySQL: " .mysqli_connect_error(); }
  33. $sql = "SELECT * FROM " . $parametro;
  34.  
  35. if ($result = mysqli_query($con, $sql))
  36. {
  37.  
  38. while($row = $result->fetch_object())
  39. {
  40. foreach($row as $key => $col){
  41. $col_array[$key] = utf8_encode($col);
  42. }
  43. $row_array[] = $col_array;
  44.  
  45. }
  46. echo json_encode($row_array);
  47. }
  48. mysqli_close($con);
  49. ?>
  50.  
  51. $resultArray = array_map('utf8_encode', $resultArray);
  52.  
  53. $result = converteArrayParaUtf8($result); //chama a função
  54. return json_encode($result); //retorna
  55.  
  56. function converteArrayParaUtf8($result){
  57. array_walk_recursive($result, function(&$item,$key){
  58. if (!mb_detect_encoding($item, 'utf-8', true)) {
  59. $item = utf8_encode($item);
  60. }
  61. });
  62. return $result;
  63. }
Add Comment
Please, Sign In to add comment