Hi, there is another ways to do that, but this will work for you:
<?
function getStrByPosition($string, $iniPosition, $endPosition){
$length = $endPosition - $iniPosition;
$subStr = Substr($string, $iniPosition, $length);
return $subStr;
}
//change the content, startTag and endTag variable according to you necessity.
$content = "How many [answer]CARS[/answer] do you have?";
$startTag = "[answer]";
$endTag = "[/answer]";
// From here, you don't need to modify
$tg1 = ereg ($startTag, $content); // return true if [answer] is found anywhere in the $content
$tg2 = ereg ($endTag, $content); // return true if [/answer] is found anywhere in the $content
if ($tg1 && $tg2){
echo "The string is: $content<BR>";
$subStr = getStrByPosition($content, strpos($content,$startTag)+strlen($startTag), strpos($content,$endTag));
echo $subStr . " was copy from the string...";
} else {
echo "The start or the end tag was not found!";
}
?>