0

I have an object that has a lot of accents in it and I'm trying to remove it but I couldn't figure out on how to do it. I need to remove the accents so I could save the values into my DB. the code bellow is how I get the values from another companies API and here is how the object looks like

Object.

I selected the part that has an accent in it

    session_start();

    $email = "EMAIL";
    $password = "PASSWORD";

    $url = "{$email}:{$password}@www.WEBSITE.eu/generator/catalog/xml";

    $xml = simplexml_load_string(file_get_contents($url));;
    $xml->preserveWhiteSpace = false;
    $xml->formatOutput = true;
    $xml->saveXML();
    //echo '<pre>'. print_r($xml->PRODUCT, true). '</pre>';
//    var_dump($xml->PRODUCT);



    $lenght = count($xml);

    for ($x = 0; $x <= $lenght; $x++) {
      $product = SaveProduct($xml->PRODUCT[$x]);
    }
Scriptable
  • 19,402
  • 5
  • 56
  • 72
  • 1
    Maybe you should fix your database? What's the reason that you can't store accented texts in database? – u_mulder Jul 12 '22 at 14:54
  • @u_mulder i'm getting an error `have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'Eté','50ml','','','','W','http://www.prodejparfemu.cz/shopimg/387/493254_coco' at line 1` So I thought that it was an accent problem – Emin Ozdogan Jul 12 '22 at 14:57
  • Show the SQL which give you the error – executable Jul 12 '22 at 15:04
  • That's obviously has nothing to do with accents. What you need is __prepared statements__ instead of adding values to query string. Read [this related question](/questions/60174/how-can-i-prevent-sql-injection-in-php) – u_mulder Jul 12 '22 at 15:05

0 Answers0