Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP] Jak programować
Jo-Jo
post
Post #1





Grupa: Zarejestrowani
Postów: 3
Pomógł: 0
Dołączył: 31.07.2012

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


Zabrałem się za prace Inżynierską (specjalistyczny CMS)
Zacznę od tego ze moja znajomość PHP pozwala żeby go napisać
Pytanie brzmi czy moje rozwiązanie jest tym najlepszym

Parę pytań na początek:

(chodzi o wprowadzanie danych w Panelu Admina)
Walidacja formularzy
Czy sprawdzać każdą zmienną przez preg_match?
a może warto robić to w Java Script?
lub wystarczy za pomocą PDO chronić się przed sql injection, a co wprowadzi użytkownik w danym polu jest nie ważne?
a może inna metoda?

Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
wNogachSpisz
post
Post #2





Grupa: Zarejestrowani
Postów: 1 233
Pomógł: 87
Dołączył: 6.03.2009

Ostrzeżenie: (40%)
XX---


Cytat(Jo-Jo @ 31.07.2012, 22:24:17 ) *
wszystkie rozwiązania jakie znalazłem na walidacje polskich liter właśnie tak wyglądały

Smutne ale prawdziwe. Jakość sniptów produkcji krajowej jest zatrważająca.

Cytat(Jo-Jo @ 31.07.2012, 22:24:17 ) *
i o ile kody ASCII liter sobie wyciągnę, to nie wiem jak je zastosować w preg_match

Musisz zrobić normalizację UTF-8, a potem już z górki :-]

Gotowca nie dam, ale polskie znaki usuwam tym sposobem:
  1. <?php
  2.  
  3. require 'I18N/UnicodeNormalizer.php';
  4. $normalizer = new I18N_UnicodeNormalizer(); // z PEAR
  5.  
  6. function diacritic_replace( $s ) {
  7.  
  8. global $normalizer;
  9.  
  10. // maps German (umlauts) and other European characters onto two characters before just removing diacritics
  11. $s = preg_replace( '@\x{00c4}@u' , "AE", $s ); // umlaut � => AE
  12. $s = preg_replace( '@\x{00d6}@u' , "OE", $s ); // umlaut � => OE
  13. $s = preg_replace( '@\x{00dc}@u' , "UE", $s ); // umlaut � => UE
  14. $s = preg_replace( '@\x{00e4}@u' , "ae", $s ); // umlaut � => ae
  15. $s = preg_replace( '@\x{00f6}@u' , "oe", $s ); // umlaut � => oe
  16. $s = preg_replace( '@\x{00fc}@u' , "ue", $s ); // umlaut � => ue
  17. $s = preg_replace( '@\x{00f1}@u' , "ny", $s ); // ń => ny
  18. $s = preg_replace( '@\x{00ff}@u' , "yu", $s ); // ˙ => yu
  19.  
  20. // maps special characters (characters with diacritics) on their base-character followed by the diacritical mark
  21. // exmaple: � => U�, � => a`
  22.  
  23. $s = $normalizer->normalize($s, 'NFD', 'UTF-8');
  24.  
  25. $s = preg_replace( '@\pM@u' , "", $s ); // removes diacritics
  26.  
  27. $s = preg_replace( '@\x{00df}@u' , "ss", $s ); // maps German � onto ss
  28. $s = preg_replace( '@\x{00c6}@u' , "AE", $s ); // Ć => AE
  29. $s = preg_replace( '@\x{00e6}@u' , "ae", $s ); // ć => ae
  30. $s = preg_replace( '@\x{0132}@u' , "IJ", $s ); // ? => IJ
  31. $s = preg_replace( '@\x{0133}@u' , "ij", $s ); // ? => ij
  32. $s = preg_replace( '@\x{0152}@u' , "OE", $s ); // Œ => OE
  33. $s = preg_replace( '@\x{0153}@u' , "oe", $s ); // œ => oe
  34.  
  35. $s = preg_replace( '@\x{00d0}@u' , "D", $s ); // Đ => D
  36. $s = preg_replace( '@\x{0110}@u' , "D", $s ); // Đ => D
  37. $s = preg_replace( '@\x{00f0}@u' , "d", $s ); // đ => d
  38. $s = preg_replace( '@\x{0111}@u' , "d", $s ); // d => d
  39. $s = preg_replace( '@\x{0126}@u' , "H", $s ); // H => H
  40. $s = preg_replace( '@\x{0127}@u' , "h", $s ); // h => h
  41. $s = preg_replace( '@\x{0131}@u' , "i", $s ); // i => i
  42. $s = preg_replace( '@\x{0138}@u' , "k", $s ); // ? => k
  43. $s = preg_replace( '@\x{013f}@u' , "L", $s ); // ? => L
  44. $s = preg_replace( '@\x{0141}@u' , "L", $s ); // L => L
  45. $s = preg_replace( '@\x{0140}@u' , "l", $s ); // ? => l
  46. $s = preg_replace( '@\x{0142}@u' , "l", $s ); // l => l
  47. $s = preg_replace( '@\x{014a}@u' , "N", $s ); // ? => N
  48. $s = preg_replace( '@\x{0149}@u' , "n", $s ); // ? => n
  49. $s = preg_replace( '@\x{014b}@u' , "n", $s ); // ? => n
  50. $s = preg_replace( '@\x{00d8}@u' , "O", $s ); // Ř => O
  51. $s = preg_replace( '@\x{00f8}@u' , "o", $s ); // ř => o
  52. $s = preg_replace( '@\x{017f}@u' , "s", $s ); // ? => s
  53. $s = preg_replace( '@\x{00de}@u' , "T", $s ); // Ţ => T
  54. $s = preg_replace( '@\x{0166}@u' , "T", $s ); // T => T
  55. $s = preg_replace( '@\x{00fe}@u' , "t", $s ); // ţ => t
  56. $s = preg_replace( '@\x{0167}@u' , "t", $s ); // t => t
  57.  
  58. // remove all non-ASCii characters
  59. $s = preg_replace( '@[^\0-\x80]@u' , "", $s );
  60.  
  61. return $s;
  62. }


Ten post edytował wNogachSpisz 1.08.2012, 10:33:21
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: 17.10.2025 - 15:28