Visualizzazione dei risultati da 1 a 3 su 3
  1. #1

    codice html dentro al database

    ciauz a tutti...volevo chiedervi...come è possibile inserire del codice html in un database...senza incorrere in errori?
    è sufficiente scrivere
    Codice PHP:
                $testo mysql_real_escape_string($testo,$conn); 
    e se volessi abilitare solo alcuni tag?
    cioè...se volessi che l'utente possa utilizzare solo <ul>,[*], [b],
    ?

    ciauzzzz

  2. #2
    secondo me ti conviene far utilizzare all'utente dei tag appositi e poi con la funzione string replace rimpiazzarli con il codice html. Ad esempio, l'utente scrive

    testo normale [gras] testo in grassetto [/gras]

    e lo memorizzi nel database. Poi, quando vai a visualizzare il testo, sostituisci [gras] con [b] e lo stampi:

    Codice PHP:
    $testo str_replace("[gras]""[b]"$testo);
    $testo str_replace("[/gras]""[/b]"$testo); 

  3. #3
    ciauz, grazie della risposta...

    è che a seconda dei permessi dell'utente può utilizzare html o bbcode...

    cmq ho trovato questa funzione...e funge perfettamente...l'unico problema è che nn accetta i tag dell'xhtml
    ad esempio 'br /'

    qualcuno sa come modificare la regular expression?

    Codice PHP:
    function strip_tags_except($text$allowed_tags$strip=TRUE) {
       
    // allowing the user to specify the tags to strip, she can specify the tags to allow and strip all others. The third parameter, $strip, when TRUE removes "<" and ">" from the string and when FALSE converts them to "&lt;" and "&gt;" respectively.

      
    if (!is_array($allowed_tags))
        return 
    $text;

      if (!
    count($allowed_tags))
        return 
    $text;

      
    $open $strip '' '&lt;';
      
    $close $strip '' '&gt;';

      
    preg_match_all('!<\s*(/)?\s*([a-zA-Z]+)[^>]*>!',
        
    $text$all_tags);
      
    array_shift($all_tags);
      
    $slashes $all_tags[0];
      
    $all_tags $all_tags[1];
      foreach (
    $all_tags as $i => $tag) {
        if (
    in_array($tag$allowed_tags))
          continue;
        
    $text =
          
    preg_replace('!<(\s*' $slashes[$i] . '\s*' .
            
    $tag '[^>]*)>!'$open '$1' $close,
            
    $text);
      }

      return 
    $text;

    ciauzzz

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.