How do i implement htmlspecialchars for a textbox value?

Hello i’m currently using a table to input values into a custom meta field. I have a text box called episode title. My problem here is that if the characters ‘ ” are added in the field then everything goes in to chaos. I want to use the htmlspecialchars to input the values as &quot and &#039 instead of ‘ “. the below code does not work to covert the characters. Can anyone please help?

    <p>
      <input type="text" name="episode_title[]" id="episode_title[]" value="<?php echo ($_POST['episode_title']); ?>" class="title regular-text" style="width: 98%" />
      <span class="description"><?php _e('Title of The Episode.'); ?></span>
    </p>    

Related posts

Leave a Reply

2 comments

  1. add this to the htmlspecialchars call: ENT_QUOTES like so:

    <?php echo htmlspecialchars($_POST['episode_title'], ENT_QUOTES); ?>
    

    This will enable changing of both the " and the ' quotes

  2. $_POST['episode_title'] is an array, so you need to get the right value from the array and use htmlspecialchars() on that value.

    Something like:

    value="<?php echo htmlspecialchars($_POST['episode_title'][$some_key]); ?>"
    

    Edit: I am assuming that the $_POST array contains the results of the form when it is submitted.