Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [php][html]Wycinanie tagów
redelek
post
Post #1





Grupa: Zarejestrowani
Postów: 658
Pomógł: 37
Dołączył: 4.06.2005
Skąd: Wawa

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


Witam,

Mam taki formularz
  1. <meta http-equiv="content-type" content="text/html; charset=ISO8859-2">
  2. <meta name="generator" content="PSPad editor, www.pspad.com">
  3. </head>
  4. <body>
  5. <form action="form.php" method="post" enctype="multipart/form-data">
  6.  
  7. Tytuł: <input name="f_tytul" type="text" size="45" maxlength="45"><br>
  8. Opis:<br>
  9. <textarea name="f_opis" cols="45" rows="8"></textarea><br>
  10. Linki:<br>
  11. <textarea name="f_linki" cols="45" rows="8"></textarea><br>
  12. <input name="Wyslij" type="submit" value="Wyľlij">
  13.  
  14.  
  15. </form>
  16. </body>


Dane są przesyłane do skryptu i chodzi mi o usunięcie tagów html wstawionych w pola f_opis i f_linki. Dozwolone znaki to <b><i><u>.
Czy można to jakoś zrobić. ?


Dzięki
Redelek

Bawiłem się stripslashes i addslashes, ale to nie to albo nie umiem zastosować tego

Ten post edytował redelek 12.09.2007, 16:27:05


--------------------
Pozdrawiam
Piotrek R
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 6)
lectric
post
Post #2





Grupa: Zarejestrowani
Postów: 167
Pomógł: 1
Dołączył: 22.08.2006
Skąd: universe

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


Taka oto funkcja:

  1. <?php
  2. function taghtml($str)
  3. {
  4. $approvedtags = array(
  5. "p"=>2, 
  6. "b"=>1,
  7. "i"=>1,
  8. "a"=>1,
  9. "em"=>1,
  10. "br"=>1,
  11. "strong"=>1,
  12. "blockquote"=>1,
  13. "tt"=>1,
  14. "hr"=>1,
  15. "li"=>1,
  16. "ol"=>1,
  17. "ul"=>1
  18. );
  19.  
  20. $str = stripslashes($str);
  21. $str = eregi_replace("<[[:space:]]*([^>]*)[[:space:]]*>","<1>",$str);
  22. $str = eregi_replace("<a([^>]*)href=\"?([^\"]*)\"?([^>]*)>",
  23. "<a href=\"2\">", $str);
  24. $tmp = "";
  25. while (eregi("<([^> ]*)([^>]*)>",$str,$reg))
  26. {
  27. $i = strpos($str,$reg[0]);
  28. $l = strlen($reg[0]);
  29. if ($reg[1][0] == "/")
  30. $tag = strtolower(substr($reg[1],1));
  31. else
  32. $tag = strtolower($reg[1]);
  33. if ($a = $approvedtags[$tag])
  34. if ($reg[1][0] == "/")
  35. $tag = "</$tag>";
  36. elseif ($a == 1)
  37. $tag = "<$tag>";
  38. else
  39. $tag = "<$tag " . $reg[2] . ">";
  40. else
  41. $tag = "";
  42. $tmp .= substr($str,0,$i) . $tag;
  43. $str = substr($str,$i+$l);
  44. }
  45. $str = $tmp . $str;
  46.  
  47.  
  48. $str = ereg_replace("<?","",$str);
  49. return $str;
  50. }
  51. ?>


ustaw sobie w tablicy zezwolenia.


--------------------
Potrzebujesz dodać darmowe ogłoszenia ?, w takim razie musisz odwiedzić to miejsce !
Presell - tutaj dodasz swoj artykul za darmo ! Presell Page dla wszystkich bez limitów i utrudnień
Masz firme ? Ta baza firm jest dla Ciebie i Twoich znajomych są też śmieszne filmiki
Go to the top of the page
+Quote Post
redelek
post
Post #3





Grupa: Zarejestrowani
Postów: 658
Pomógł: 37
Dołączył: 4.06.2005
Skąd: Wawa

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


Cytat(lectric @ 12.09.2007, 15:32:26 ) *
Taka oto funkcja:

  1. <?php
  2. function taghtml($str)
  3. {
  4. $approvedtags = array(
  5. "p"=>2, 
  6. "b"=>1,
  7. "i"=>1,
  8. "a"=>1,
  9. "em"=>1,
  10. "br"=>1,
  11. "strong"=>1,
  12. "blockquote"=>1,
  13. "tt"=>1,
  14. "hr"=>1,
  15. "li"=>1,
  16. "ol"=>1,
  17. "ul"=>1
  18. );
  19.  
  20. $str = stripslashes($str);
  21. $str = eregi_replace("<[[:space:]]*([^>]*)[[:space:]]*>","<1>",$str);
  22. $str = eregi_replace("<a([^>]*)href=\"?([^\"]*)\"?([^>]*)>",
  23. "<a href=\"2\">", $str);
  24. $tmp = "";
  25. while (eregi("<([^> ]*)([^>]*)>",$str,$reg))
  26. {
  27. $i = strpos($str,$reg[0]);
  28. $l = strlen($reg[0]);
  29. if ($reg[1][0] == "/")
  30. $tag = strtolower(substr($reg[1],1));
  31. else
  32. $tag = strtolower($reg[1]);
  33. if ($a = $approvedtags[$tag])
  34. if ($reg[1][0] == "/")
  35. $tag = "</$tag>";
  36. elseif ($a == 1)
  37. $tag = "<$tag>";
  38. else
  39. $tag = "<$tag " . $reg[2] . ">";
  40. else
  41. $tag = "";
  42. $tmp .= substr($str,0,$i) . $tag;
  43. $str = substr($str,$i+$l);
  44. }
  45. $str = $tmp . $str;
  46. $str = ereg_replace("<?","",$str);
  47. return $str;
  48. }
  49. ?>


ustaw sobie w tablicy zezwolenia.

DZIĘKUJĘ exclamation.gif!!


--------------------
Pozdrawiam
Piotrek R
Go to the top of the page
+Quote Post
lectric
post
Post #4





Grupa: Zarejestrowani
Postów: 167
Pomógł: 1
Dołączył: 22.08.2006
Skąd: universe

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


proszę, następnym razem nie cytuj w taki sposob.


--------------------
Potrzebujesz dodać darmowe ogłoszenia ?, w takim razie musisz odwiedzić to miejsce !
Presell - tutaj dodasz swoj artykul za darmo ! Presell Page dla wszystkich bez limitów i utrudnień
Masz firme ? Ta baza firm jest dla Ciebie i Twoich znajomych są też śmieszne filmiki
Go to the top of the page
+Quote Post
redelek
post
Post #5





Grupa: Zarejestrowani
Postów: 658
Pomógł: 37
Dołączył: 4.06.2005
Skąd: Wawa

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


Cytat(lectric @ 12.09.2007, 15:35:18 ) *
proszę, następnym razem nie cytuj w taki sposob.


Nie wiem jak, ale postaram się smile.gif dzięki serdeczne


--------------------
Pozdrawiam
Piotrek R
Go to the top of the page
+Quote Post
mild
post
Post #6





Grupa: Zarejestrowani
Postów: 78
Pomógł: 0
Dołączył: 22.04.2007
Skąd: Wrocław

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


Nie łatwiej użyć strip_tags?
Go to the top of the page
+Quote Post
qqrq
post
Post #7





Grupa: Zarejestrowani
Postów: 418
Pomógł: 8
Dołączył: 16.11.2006

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


redelek => lectricowi zapewne chodziło żebyś nie wklejał całego poprzedniego postu (bo po co), zmniejszasz czytelność forum... Nawiasem mówiąc mild ma chyba rację - strip_tags jest funkcją której (chyba) szukasz

Ten post edytował qqrq 12.09.2007, 17:14:33


--------------------
Go to the top of the page
+Quote Post

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

 



RSS Aktualny czas: 19.08.2025 - 15:41