3v4l.org

run code in 300+ PHP versions simultaneously
<?php $string = 'pippo ASC, `table`.`pippo` DESC, campo.discendente DESC, `tabella`.`asc` ASC'; $string = preg_replace_callback('#(![\`]+)\b(ASC|DESC)\b#i', function($match) { switch(strtoupper($match[1])) { case 'ASC': return 'DESC'; case 'DESC': return 'ASC'; } }, $string); echo $string;

preferences:
48.17 ms | 402 KiB | 5 Q