You can change the way you generate the string by breaking the it up in to the separate parts (static and dynamic) and concatenating the parts together with .
textinjector($filedirectory, 23, '{ "title": ".' . $PageTitle . '", "url": "/.' . $PageTitle . "https://stackoverflow.com/" },');
3
solved How do i make all the ‘ symbols into ” while still detecting the variables in PHP? [closed]