<?php
$texte="<balise name=\"header\" type=\"integer\">Utiliser des regexp via PHP</balise>";
eregi("<balise(.*)name=(\"|')(.*)(\"|')(.*)>(.*)</balise>", $texte, $regs);
var_dump($regs);
?>
Voici le resultat de ce script:Code : Tout sélectionner
array(7) {
[0]=>
string(58) "<balise name="header" type="integer">Utiliser des regexp via PHP</balise>"
[1]=>
string(1) " "
[2]=>
string(1) """
[3]=>
string(21) "header" type="integer"
[4]=>
string(1) """
[5]=>
bool(false)
[6]=>
string(27) "Utiliser des regexp via PHP"
}Code : Tout sélectionner
array(7) {
[0]=>
string(73) "<balise name="header" type="integer">Utiliser des regexp via PHP</balise>"
[1]=>
string(1) " "
[2]=>
string(1) """
[3]=>
string(6) "header"
[4]=>
string(1) """
[5]=>
string(15) " type="integer""
[6]=>
string(27) "Utiliser des regexp via PHP"
}<?php
$texte = "<balise name=\"header\" type=\"integer\">Utiliser des regexp via PHP</balise>";
$masque = "#<balise(.*)name=(\"|')(\w*)(\"|')(\s?.*)>(.*)</balise>#i";
preg_match($masque, $texte, $regs);
?>
<pre>
<?php
var_dump($regs);
?>
</pre>
Le résultat :Code : Tout sélectionner
array(7) {
[0]=>
string(73) "<balise name="header" type="integer">Utiliser des regexp via PHP</balise>"
[1]=>
string(1) " "
[2]=>
string(1) """
[3]=>
string(6) "header"
[4]=>
string(1) """
[5]=>
string(15) " type="integer""
[6]=>
string(27) "Utiliser des regexp via PHP"
}
Code : Tout sélectionner
<balise name="header">Utilisez PHP</balise><balise name="footer">Utilisez MySQL</balise>Code : Tout sélectionner
array(2) {
[0]=>
array(6) {
[0]=>
string(43) "<balise name="header">Utilisez PHP</balise>"
[1]=>
string(1) " "
[2]=>
string(1) """
[3]=>
string(6) "header"
[4]=>
string(1) """
[5]=>
string(12) "Utilisez PHP"
}
[1]=>
array(6) {
[0]=>
string(45) "<balise name="footer">Utilisez MySQL</balise>"
[1]=>
string(1) " "
[2]=>
string(1) """
[3]=>
string(6) "footer"
[4]=>
string(1) """
[5]=>
string(14) "Utilisez MySQL"
}
}$this->tempOne = array( "<balise name=\"header\">Utilisez PHP</balise>", " ", "\"", "header", "\"", "Utilisez PHP" );
$this->tempTwo = array( "<balise name=\"footer\">Utilisez MySQL</balise>", " ", "\"", "footer", "\"", "Utilisez MySQL" );
$this->parsed = array( $this->tempOne, $this->tempTwo );
private function parse( $themesFolder, $themesFile )
{
$this->themesFolder = $themesFolder;
$this->themesFile = $themesFile;
$this->contents = $this->getFile( $this->themesFolder, $this->themesFile );
if ( ! preg_match_all( "#<template(.*)name=(\"|')(\w*)(\"|')>(.*)</template>#is", $this->contents, $this->parsed, PREG_SET_ORDER ) )
{
$this->functionsClass->errorReport( 3, __FILE__, __LINE__ - 2, "main.xml' or '".$this->themesFile.".xml' in '".$this->themesFolder );
}
return $this->parsed;
}
La fonction getFile() retourne le contenu du fichier XML.