Une autre façon très simple est de créer une fonction simple qui peut être invoquée à tout moment.
<?php
// Create the Function to get the string
function GetStringBetween ($string, $start, $finish) {
$string = " ".$string;
$position = strpos($string, $start);
if ($position == 0) return "";
$position += strlen($start);
$length = strpos($string, $finish, $position) - $position;
return substr($string, $position, $length);
}
?>
et est ici un exemple d'utilisation pour votre question
$string1="
{desc=1}
This is a description
{/desc}";
$string2="
{desc=1}
This is a description
{/desc}
{desc=2}
other description
{/desc}";
echo GetStringBetween ($string1, "{desc=1}", "{/desc}");
echo GetStringBetween ($string2, "{desc=1}", "{/desc}");
echo GetStringBetween ($string2, "{desc=2}", "{/desc}");
Pour plus de détails s'il vous plaît lire http://codetutorial.com/howto/how-to-get-of-everything-string-between-two-tag-or-two-strings.
Vous devez utiliser XML. Cela rendrait tout plus facile. – esqew
Peuvent-ils être imbriqués? – Dogbert
@Dogbert: Non, il ne peut pas –