par
newphpman » 10 nov. 2010, 16:30
Bonjour j'ai un petit problème,
j'essaie de créer un script qui m'affiche tout les titres d'une page html en enlevant les balises.
voila mon code:
$motif = '#(<(h[1-6]).*>)(.+)(<\/\2>)#';
if (isset($_SERVER['argv'][1]))
{
$file = $_SERVER['argv'][1];
if (file_exist($file) &&
file_nodir($file) &&
fileis_readable($file))
{
$fd = fopen($file, 'r');
if ($fd !== false)
{
$tmp = fread($fd, filesize($file));
if ($tmp !== false)
{
preg_match_all($motif, $tmp, $res);
print_r($res);
}
}
fclose($fd);
}
}
et je ne comprends pas pourquoi dans mon tableau de resultat, j'ai mon $res[1] qui n'est pas == à <h1>
Array
(
[0] => Array
(
[0] => <h1>Ceci est <u>un test</u></h1>
[1] => <h1 style="display:block; font-weight:700; font-size:26;">Niveau H1</h1>
[2] => <h2 style="display:block; font-weight:700; font-size:20;">Niveau H2</h2>
[3] => <h3>Niveau H3</h3>
[4] => <h4>Niveau H4</h4>
[5] => <h5>Niveau H5</h5>
[6] => <h6>Niveau H6</h6>
)
[1] => Array
(
[0] => <h1>Ceci est <u>
[1] => <h1 style="display:block; font-weight:700; font-size:26;">
[2] => <h2 style="display:block; font-weight:700; font-size:20;">
[3] => <h3>
[4] => <h4>
[5] => <h5>
[6] => <h6>
mon expression est peut etre pas bonne mais la je vois pas! quelqu'un pour m'aider?
Bonjour j'ai un petit problème,
j'essaie de créer un script qui m'affiche tout les titres d'une page html en enlevant les balises.
voila mon code:
$motif = '#(<(h[1-6]).*>)(.+)(<\/\2>)#';
if (isset($_SERVER['argv'][1]))
{
$file = $_SERVER['argv'][1];
if (file_exist($file) &&
file_nodir($file) &&
fileis_readable($file))
{
$fd = fopen($file, 'r');
if ($fd !== false)
{
$tmp = fread($fd, filesize($file));
if ($tmp !== false)
{
preg_match_all($motif, $tmp, $res);
print_r($res);
}
}
fclose($fd);
}
}
et je ne comprends pas pourquoi dans mon tableau de resultat, j'ai mon $res[1] qui n'est pas == à <h1>
Array
(
[0] => Array
(
[0] => <h1>Ceci est <u>un test</u></h1>
[1] => <h1 style="display:block; font-weight:700; font-size:26;">Niveau H1</h1>
[2] => <h2 style="display:block; font-weight:700; font-size:20;">Niveau H2</h2>
[3] => <h3>Niveau H3</h3>
[4] => <h4>Niveau H4</h4>
[5] => <h5>Niveau H5</h5>
[6] => <h6>Niveau H6</h6>
)
[1] => Array
(
[color=#FF0000][0] => <h1>Ceci est <u>[/color]
[1] => <h1 style="display:block; font-weight:700; font-size:26;">
[2] => <h2 style="display:block; font-weight:700; font-size:20;">
[3] => <h3>
[4] => <h4>
[5] => <h5>
[6] => <h6>
mon expression est peut etre pas bonne mais la je vois pas! quelqu'un pour m'aider?