How to escape single quotes in a translated array
-
Can anyone tell me how to escape the single quotes in a variable for the returned translated array?
Apparently it isn't working with a backslash like this:$pages = 'Pagina\'s'; return [ 'pages' => $pages, ]
nor does it work with double quotes
$pages = "Pagina\'s"; return [ 'pages' => $pages, ]
-
Try to use the php function addslashes()
<?php $pages = "Pagina's"; $array = [ 'pages' => addslashes($pages), ]; print_r($array);
This will return
Array ( [pages] => Pagina\'s )
-
@ghermans said in How to escape single quotes in a translated array:
addslashes(
$currencies = "Valuta's"; $locales = "Talen"; return [ 'currencies' => addslashes($currencies), 'currencies-and-locales' => addslashes($currencies) . ' en ' . $locales ]
It doesn't always give the same results as you can see in the screenshot.
We get "Valuta's" and "Valuta's en Talen"