简体   繁体   中英

single quote (') returns ’ when submitting of form in codeigniter

I have a form containing textbox and textarea. If I am going to input text(using my keyboard) even if it contains special characters, it produces an exact result depending on the input. However, when I "copied" sentence or paragraph from another website contact special charactes like single quote ('), double quotes returns inappropriate result.

example: Input1 single quote(') Output is ’ Input2 double quote("") output is €œ

Here is my code

 //From my view.php 
 <?php
  echo form_open(base_url('addsong/submit') , 'onsubmit="return addsong.submitForm();" accept-charset="UTF-8"');
    ?>
        <input type="text" name="inpt">
       <textarea name="txt"></textarea>
     <?php
  echo form_close();
  ?>

    <?php
   //Model
   function insert()
   {
     $data = array(
          'input' => $this->input->post('inpt'),
          'parag' => $this->input->post('txt')
      );
      $this->db->insert('sampletbl', $data);
   }
   ?>

Try this:

function insert()
   {
     $data = array(
          'input' => htmlspecialchars($this->input->post('inpt')),
          'parag' => htmlspecialchars($this->input->post('txt'))
      );
      $this->db->insert('sampletbl', $data);
   }

This will escape those chars before inserting it in the database

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM