Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> 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
Tomplus
post
Post #2





Grupa: Zarejestrowani
Postów: 1 885
Pomógł: 231
Dołączył: 20.03.2005
Skąd: Będzin

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


Sklep oparty o własny skrypt czy jakieś Magento/Presto etc?

Poszukaj kodu który tworzy opisy w meta tagach, może coś się dopisuje. (jakie powinno być słowo tam gdzie ucina się opis)

Go to the top of the page
+Quote Post
d4ng
post
Post #3





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

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


Sklep stoi na Opencart i ktoś kto wprowadzał opisy robił kopiuj wklej przez co wpadł tekst z krzakami... ale nawet po wyczyszczeniu tekstu ł wyświetla się jako znak specjalny... zastanawiam się czy można użyć jakiegoś dekodera żeby przekombinował niewłaściwe znaki w ostateczności podmienię je na froncie ale tego nie chciałbym robić...
Go to the top of the page
+Quote Post
d4ng
post
Post #4





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
nospor
post
Post #5





Grupa: Moderatorzy
Postów: 36 561
Pomógł: 6315
Dołączył: 27.12.2004




Napisano ci, bys uzywal funkcji z rodziny mb_

czyli np. nie
substr
a
mb_substr

analogicznie reszta funkcji dzialajacych na tekscie
Go to the top of the page
+Quote Post
d4ng
post
Post #6





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

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


działa (IMG:style_emoticons/default/smile.gif) dziękuje (IMG:style_emoticons/default/smile.gif)

rozumiem że header('Content-Type: text/html; charset=utf-8'); i $desc = mb_convert_encoding($desc, "UTF-8"); moge sie już pozbyć?
Go to the top of the page
+Quote Post
nospor
post
Post #7





Grupa: Moderatorzy
Postów: 36 561
Pomógł: 6315
Dołączył: 27.12.2004




Dobrze by strona wysylala naglowek o kodowaniu. Jesli robisz to gdzies indziej, to wywal.
Go to the top of the page
+Quote Post

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: 22.12.2025 - 08:15