Soit un code html, n’importe lequel, obtenu depuis un formulaire…
code html d’exemple :
<h2>
<a href="index.html">
<font color="#0000ff"><i>Open</i></font><font color="#000084">BSD</font>
</a>
<font color="#e00000">macppc</font>
</h2>
<hr>
<p>
OpenBSD/macppc runs on the PowerPC-based Macintosh systems from the
<i>``New World''</i> family, i.e. all Apple computers from the iMac to current
models. It does not run on any <a href="#unsup">unsupported models</a>.
<p>
A mailing list dedicated to the OpenBSD/macppc port is available at
<u><font color="#23238e">ppc@openbsd.org</font></u>.
To join the OpenBSD/macppc mailing list, send a message body of <b>"subscribe
ppc"</b> to
<a href="mailto:majordomo@openbsd.org">majordomo@openbsd.org</a>.
Please be sure to check our <a href="mail.html">mailing list policy</a> before
subscribing.
<br clear=all>
<hr>
<h3 id="history"><font color="#0000e0"><strong>History:</strong></font></h3>
<p>
The OpenBSD/macppc port started as OpenBSD/powerpc, and was initially
focused on Motorola computers with Open Firmware, and VI Power4e boards.
This port was eventually thrown away after OpenBSD 2.5 was released.
As a result there was no OpenBSD/powerpc port for the 2.6 and 2.7 releases.
In the meantime, a new port was started, focusing on Apple hardware, and
based on code from NetBSD/macppc, and after a lot of work from Dale Rahn,
OpenBSD 2.8 was released with a powerpc port.
As work on the port continued, it was renamed to OpenBSD/macppc for 3.0.
Support for the 64-bit G5 (running in 32-bit mode) was added in OpenBSD 3.9.
<hr>
(rohhh, la purée de promotion…)
La variable post est filtrée ainsi, en PHP :
$thtml = filter_var( $_POST['thtml'], FILTER_SANITIZE_FULL_SPECIAL_CHARS );
La variable $thtml est bien de type ‘string’, ce que confirme le retour ci-dessous…
Ensuite, j’utilise le code PHP suivant :
$array = preg_split('#<(/?)([^>]*)>#', $thtml, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
var_dump($array);
Le retour de la function ‘‘var_dump()’’ est celui-ci :
array(1) { [0]=> string(1882) "<h2> <a href="index.html"> <font color="#0000ff"><i>Open</i></font><font color="#000084">BSD</font> </a> <font color="#e00000">macppc</font> </h2> <hr> <p> OpenBSD/macppc runs on the PowerPC-based Macintosh systems from the <i>``New World''</i> family, i.e. all Apple computers from the iMac to current models. It does not run on any <a href="#unsup">unsupported models</a>. <p> A mailing list dedicated to the OpenBSD/macppc port is available at <u><font color="#23238e">ppc@openbsd.org</font></u>. To join the OpenBSD/macppc mailing list, send a message body of <b>"subscribe ppc"</b> to <a href="mailto:majordomo@openbsd.org">majordomo@openbsd.org</a>. Please be sure to check our <a href="mail.html">mailing list policy</a> before subscribing. <br clear=all> <hr> <h3 id="history"><font color="#0000e0"><strong>History:</strong></font></h3> <p> The OpenBSD/macppc port started as OpenBSD/powerpc, and was initially focused on Motorola computers with Open Firmware, and VI Power4e boards. This port was eventually thrown away after OpenBSD 2.5 was released. As a result there was no OpenBSD/powerpc port for the 2.6 and 2.7 releases. In the meantime, a new port was started, focusing on Apple hardware, and based on code from NetBSD/macppc, and after a lot of work from Dale Rahn, OpenBSD 2.8 was released with a powerpc port. As work on the port continued, it was renamed to OpenBSD/macppc for 3.0. Support for the 64-bit G5 (running in 32-bit mode) was added in OpenBSD 3.9. <hr>" }
Il me semblait avoir compris qu’en utilisant le pattern suivant <(/?)([^>]*)>
, je construisais un tableau à chaque tag qu’il trouve dans le code HTML posté !
Apparemment, non !
Puisque comme on peut le remarquer, je n’ai qu’une seule clé dans mon tableau !
Quid ?