Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> problem ze znakiem specjalnym � na końcu stringu...
d4ng
post
Post #1





Grupa: Zarejestrowani
Postów: 191
Pomógł: 4
Dołączył: 7.03.2010

Ostrzeżenie: (0%)
-----


Witajcie, w osobnym pliku php pobieram dane z bazy sklepu internetowego i inkluduje je w innym pliku php bloga. Dane sa ok tylko na końcu przykleja mi się znak specjalny :/ np "Udoskonalona perłowa receptura Aloesowego mydła w płynie do rąk, znacząco podwyższona si�..." Html posiada poprawne meta.
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
d4ng
post
Post #2





Grupa: Zarejestrowani
Postów: 191
Pomógł: 4
Dołączył: 7.03.2010

Ostrzeżenie: (0%)
-----


mój kod, od razu powiedzcie co zrobiłem górką bo już próbowałem wszystkiego co znalazłem... ps. dlaczego funkcja rand() czesto zwraca mi te same liczby? można na to wpłynąć np przez dodanie aktualnego czasu jako hmm soli?

  1. <?php
  2. header('Content-Type: text/html; charset=utf-8');
  3.  
  4. $servername = "gfdsfgdfsgsdf";
  5. $username = "fgdsfdgsfg";
  6. $password = "dfgdsfgsdfgsr";
  7. $dbname = "fdgfdsgdfsgsdfg";
  8.  
  9. // Create connection
  10. $conn = new mysqli($servername, $username, $password, $dbname);
  11. // Check connection
  12. if ($conn->connect_error) {
  13. die("Connection failed: " . $conn->connect_error);
  14. }
  15.  
  16. $sql = "SELECT p.product_id, p.image, pd.name, pd.description, ua.keyword FROM oc_product p LEFT JOIN oc_product_description pd ON (p.product_id = pd.product_id) LEFT JOIN oc_url_alias ua ON (CONCAT('product_id=', p.product_id) = ua.query) WHERE pd.language_id = '1' AND pd.description <> '' AND p.image <> '' GROUP BY p.product_id ORDER BY pd.name ASC";
  17. $result = $conn->query($sql);
  18. $rowsCount = $result->num_rows;
  19.  
  20. $unique_products = [];
  21.  
  22. if ($rowsCount > 0) {
  23. while ( $row = $result->fetch_assoc() ){
  24. $products[] = $row;
  25. }
  26.  
  27. $x = 1;
  28. $lastId = 0;
  29.  
  30. while($x <= 3) {
  31. $index = mt_rand(0, $rowsCount);
  32. $desc = $products[$index]['description'];
  33. $desc = strip_tags(html_entity_decode($desc));
  34. $desc = mb_convert_encoding($desc, "UTF-8");
  35. //utf8_encode($desc);
  36. if ( array_search($products[$index]['name'], $unique_products) == ''){
  37. if($products[$index]['image'] != '' && strlen($desc) > 50 && $index != $lastId){
  38. $html = '<div class="products--item">'
  39. .'<div class="products--image">'
  40. .'<img src="https://example.com/image/'. $products[$index]['image'] .'" alt="'. $products[$index]['name'] .'"/>'
  41. .'</div>'
  42. .'<div class="products--content">'
  43. .'<a href="https://example.com/'. $products[$index]['keyword'] .'"><h3>'. $products[$index]['name'] .'</h3></a>'
  44. .'<p>'. substr($desc, 0, 100) . '...</p>'
  45. .'</div>'
  46. .'</div>';
  47. echo $html;
  48. $lastId = $index;
  49. $x++;
  50. array_push($unique_products, $products[$index]['name']);
  51. }
  52. }
  53.  
  54. }
  55.  
  56.  
  57. } else {
  58. return null;
  59. }
  60.  
  61. $conn->close();
  62. ?>
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 28.12.2025 - 19:32