Answer the question
In order to leave comments, you need to log in
How to replace a short tag with a file connection?
For example: in the text of an article there is such a short tag {module=name}
How to write a regular expression so that the 'name.php' file from the 'modules/' folder is included instead of the short tag?
If possible, the entire preg_replace function
Answer the question
In order to leave comments, you need to log in
$content = '... {module=module1} ... {module=header} ... {module=footer_box} ...';
$replaced = preg_replace_callback( '/{module=(.*)}/U', function ( $matches ) {
$moduleName = $matches[ 1 ];
// Делаем что нужно
return '>>Заменили:' . $moduleName . '<<';
}, $content );
echo $replaced;
... >>Заменили:module1<< ... >>Заменили:header<< ... >>Заменили:footer_box<< ...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question