I built a function that will capture text between brackets and output them as an array. But the problem is that my function is only executed for the first time in a string.
function GetBetween($content,$start,$end){ $r = explode($start, $content); if (isset($r[1])){ $r = explode($end, $r[1]); return $r[0]; } return ''; } function srthhcdf($string){ $innerCode = GetBetween($string, '[coupon]', '[/coupon]'); $iat = explode('&&', $innerCode); $string = str_replace('[coupon]','',$string); $string = str_replace('[/coupon]','',$string); $newtext = '<b>'.$iat[0].'</b> <i>'.$iat[1].'</i><b>'.$iat[2].'</b>'; $string = str_replace($innerCode,$newtext,$string); return $string; } $Text = srthhcdf($Text);
But it matches only the first [coupon] and [/ coupon] not the others. For example, when the line
hello world [coupon]hello && bad && world[/coupon] and also to [coupon] the && bad && world [/coupon]
He outputs
Hello world <b>hello </b> <i> bad </i><b> world</b> and also to the && bad && world.
This means that every time it replaces [coupon] and [/coupon] , but does not format the text inside them every time.
source share