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

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -