Even if that function was meant for this, which it isn't, it wouldn't do much good. You use double quotes to define a string, so you can not use them inside the string without escaping them manually. Your functions won't re-write your script for you.
You would be safe using str_replace, replacing all instances of " with \" for example, but even then your code above wouldn't execute, because as far as PHP is concerned, the variable contains
$badtext="this " and thus PHP sees the next double quote as uinnecessary, which it is. RTFM.