Question
PHP: preg_replace_callback
Does anyone know to how write this properly, or indeed if it
can be done?
In plain English ......
if $pattern = "/\{@([^\}]*)\@}/";
return preg_replace_callback($pattern,'getFileSize',$str);
else
if $pattern = "/\{:([^\}]*)\:}/";
return preg_replace_callback($pattern,'getName',$str);
Trying to search for two possible string combinations within a larger string
and run different callbacks depending on the result, within the same larger
string.
I suspect I may have to break out of the callback 'getFileSize' and branch
to 'getName' if the $pattern is wrong, but damned if I know how.
Craig
In plain English ......
if $pattern = "/\{@([^\}]*)\@}/";
return preg_replace_callback($pattern,'getFileSize',$str);
else
if $pattern = "/\{:([^\}]*)\:}/";
return preg_replace_callback($pattern,'getName',$str);
Trying to search for two possible string combinations within a larger string
and run different callbacks depending on the result, within the same larger
string.
I suspect I may have to break out of the callback 'getFileSize' and branch
to 'getName' if the $pattern is wrong, but damned if I know how.
Craig
