php - regex - prevent two characters from being adjacent -
this question has answer here:
i need replace php lines <?=[something]?>
this: <?php echo [something]; ?>
problem there can in something clause ? , < can't adjacent. kinda new regexes , wrote messy expression: \<\?\=([a-za-z0-9()=#<>\[\]\\/'"._$\?:, \-]*)([;]*)\?\>
, replaced <?php echo \1; ?>
.
it works can't match this:
<?=[something]?><tr><td><?=[something]?>
when it's in 1 line. matches whole line altogether.
any appreciated.
this code should work:
$s = '<?=[something]?><tr><td><?=[something]?>'; $s = preg_replace('/(<\?)=\s*(\[[^]]*\])\s*(\?>)/', '$1php echo $2; $3', $s); var_dump($s);
output:
string(56) "<?php echo [something]; ?><tr><td><?php echo [something]; ?>"
Comments
Post a Comment