• Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Register
  • Login
Bagisto Forum

Bagisto

  • Register
  • Login
  • Search
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups

How to escape single quotes in a translated array

Knowledge Base
2
3
351
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L
    Luc last edited by Luc 25 Nov 2020, 15:16 25 Nov 2020, 14:48

    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,
    ]
    
    1 Reply Last reply Reply Quote 0
    • ghermans
      ghermans last edited by 25 Nov 2020, 15:36

      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
      )
      
      

      Kind regards,
      Glenn Hermans

      Manager Bagisto Europe
      info@bagisto.eu

      1 Reply Last reply Reply Quote 0
      • L
        Luc last edited by 25 Nov 2020, 16:34

        @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"
        Screenshot 2020-11-25 at 17.30.15.png

        1 Reply Last reply Reply Quote 0
        3 out of 3
        • First post
          3/3
          Last post