Gracias, Wikipedia.
ShareCode
Permalink: http://www.treeweb.es/u/974/ 01/02/2011

ShareCode

1 <?php2 3 4 5 6 7 8 9 10 11  $asignacion = '( *[:|=] *)';12  13  $sin_comillas = '[^ ]*';14  $comillas_simples = "'[^']*'";15  $comillas_dobles = '"[^"]*"';16  $atributos = "(([^ |^=|^:]*)$asignacion($comillas_dobles|$comillas_simples|$sin_comillas))"; // FUNCIONA DE PUTA MADREEEERL17  18  $info1 = array();19  $pattern1 = '(([^(\[\[)]*)(\[\[([^ |^\]\]]*)([^\]\]]*)\]\])*([^\[\[]*))'; // Obtengo los tokens de texto, los tags y cadenas de atributos20  $pattern1 = '((([^\[]|\[(?!\[))*)(\[\[([^ |^\]\]]*)([^\]\]]*)\]\])*(([^\[]|\[(?!\[))*))'; // Obtengo los tokens de texto, los tags y cadenas de atributos21 22  $text1 = file_get_contents('treescript');23  //$text1 = " array[3] w[[COMPONENT atributos = 34]] holaX";24  25  preg_match_all($pattern1, $text1, $info1, PREG_SET_ORDER );26  27  print_r($info1);28  29  $parse = array();30  foreach($info1 as $i) {31  32  if (strlen($i[1])) {33  $parse[] = array(34  'type'=>'text',35  'data'=>$i[1]36  );37  }38  39  if (strlen($i[4])) {40  41  $info2 = array();42  preg_match_all($atributos, $i[5], $info2, PREG_SET_ORDER);43  $data = array();44  foreach ($info2 as $i2) {45  $key = $i2[1];46  $value = $i2[3];47  if ($value[0]=='"') {48  $value = trim($value, '"');49  } else if ($value[0]=="'") {50  $value = trim($value, "'");51  }52  53  $data[$key] = $value;54  }55  56  $parse[] = array(57  'type'=>'token',58  'data'=>$data,59  'name'=>$i[4]60  );61  }62  63  if (strlen($i[6])) {64  $parse[] = array(65  'type'=>'text',66  'data'=>$i[6]67  );68  }69  }70  71  72 73  //highlight_string(print_r($info, true));74  75  echo '<pre>';76  print_r($parse);77  78 79 80 81 /*require('class/TreeScript.class.php');82 83 $parse = TreeScript::getParse("texto uno [[MITAG uno:dfasdf dos='adf fdsas fsfsf ']] otro texto al final etc");84 85 print_r($parse);*/86 87 ?>
Enlace
El enlace para compartir es: