3v4l.org

run code in 300+ PHP versions simultaneously
<?php $string = 'this is a test \"string\" ya\'ll with a random " and \.'; echo mb_ereg_replace("([\\\"'\0])", "\\\\1", $string);

preferences:
52.55 ms | 402 KiB | 5 Q