dev/php/preg_replace.php

19 lines
517 B
PHP
Raw Normal View History

<?php
$string = '<?if($var )?>content<endif> text... text... text... <?if($var )?>content<endif> text... text... text...';
$pattern = 'var';
$replacement = 'VAR';
$pattern = '/<\?if\(\$var \)\?>([^>]*)<endif>/i';
$replacement = '<?php if($var ) { echo \'\1\';?>';
#echo preg_replace($pattern, $replacement, $string);
/*$user = preg_replace("<\?if\(\$(.*?)\)\?>(.*?)<endif>/i","<\?php if\($(.*?)\) { echo \'\2\';?>",$user);
echo $user
*/
$user="User1";
$user = preg_replace("(.*)","{1}aaa",$user);
echo $user;
?>