Share Pastebin
Guest
Public paste!

an_archi

By: a guest | Jan 10th, 2010 | Syntax: PHP | Size: 1.20 KB | Hits: 202 | Expires: Never
This paste has a previous version, view the difference. Copy text to clipboard
  1. // sanitize a title to make it match HTML specs
  2. // http://www.w3.org/TR/html4/types.html#h-6.2
  3. function cleanText($texte,$label='section') {
  4.         // strips all HTML tags
  5.         $texte = supprimer_tags($texte);
  6.  
  7.         // replace all non valid characters (non alpha-numeric, ., -, _ and :)
  8.         $texte = preg_replace('#([^a-z0-9:-_]|[!"#$%&'()*+,/;<=>?@[\\\]^`{|}~])#i', '_', $texte);
  9.  
  10.         // strips all empty characters at the beginning of the text
  11.         // the ID or NAME should start with a letter
  12.         $texte = preg_replace('#^([_0-9]+)#i', "", $texte);
  13.  
  14.         // If there's no more latin character, then we return nothing
  15.         $count = strlen(preg_replace('#([_0-9])#i', "", $texte));
  16.         if($count<1) { return false; }
  17.  
  18.         return $texte;
  19. }
  20. function balise_VALID_ID_dist($p) {
  21.         // If no alternate label is provided, we just use 'label'
  22.         if (!$label = interprete_argument_balise(1,$p)) {$label = "'label'";}
  23.  
  24.         // gets the id of the current object
  25.         $_id_objet = $p->boucles[$p->id_boucle]->primary;
  26.         $_id = champ_sql($_id_objet, $p);
  27.  
  28.         // gets the title
  29.         $_titre = champ_sql('titre', $p);
  30.  
  31.         // Use the clean title or an alternate version if no suitable title
  32.         $p->code = "((\$a = cleanText($_titre)) ? \$a : $label.'_'.$_id)";
  33.  
  34.         return $p;
  35. }