Get text within separators in a string

Hi guys

I need to extract text within two separators in a string like below:


{available_now}
this text I need to extract
{/available_now}

How can I do that?

Try this:



  $a="{available_now} 
            this text I need to extract 
         {/available_now}";

   echo $a .'<br />'; 
   
   $b = substr($a, 15); // remove "{available_now}"

   # both remove trailing "{/available_now}"
   if(0)
  {
      $b = str_replace("{/available_now}", '', $b);
   }
   else
   {
        $b = substr($b, 0, -16);
   }

   echo $b .'<br />'; 


Sorry I forgot to mention, I need to do this dynamically (i.e. the separators and text may change)

Here we go:



#======================
#
# extract text between separators
# usage:  _extract($text_with_seperators) 
# return:  text between separators
# 
#======================
function _extract($a)
{
  // find start
  $x = strpos($a, "}");
  $b = substr($a, ++$x); // remove "{any-length-text-goes-here}"

  $y = strpos($b, "{");
  $b = substr($b, 0, --$y);

  return $b;
}

// test strings in an array
$text_with_separators = array
     (
   			"{available_yesterday} this text I need to extract {/available_yesterday}",
   			"{available_now}       this text I need to extract {/available_now}",
   			"{available_tomorrow}  this text I need to extract {/available_tomorrow}",
     );

// iterate each string and show results
foreach($text_with_separators as $item)
{
	echo $item .'<br />'; 
	
	$b = _extract($item);

	echo $b .'<br /><br />';
}


// output results

{available_yesterday} this text I need to extract {/available_yesterday}
this text I need to extract

{available_now} this text I need to extract {/available_now}
this text I need to extract

{available_tomorrow} this text I need to extract {/available_tomorrow}
this text I need to extract