<?php
function repeat($text, $numRepeats)
{
if(!function_exists('repeat_repeat'))
{
function repeat_repeat($txt, $rpt)
{
$out = "";
for($i=0; $i<$rpt; $i++)
{
$out .= $txt . ' ';
}
return $out;
}
}
$search = '/__repeat\(\((.+)\)\)/Use';
$replace = "repeat_repeat('$1', $numRepeats)";
return preg_replace($search, $replace, $text);
}
// TEST
$str = "this is a string and I want to repeat __repeat((this part)) and __repeat((this part)) X number of times";
echo repeat($str, 3);