Show English characters and simple special characters only

Problem I need to fix is that if I enter characters outside English range in description textarea it shows that only 1 character is used for 1 character typed, so you can write full text area of 2000 characters, head.php script shows all (ā, ē, ī, ū, ‘) characters as 1 symbol typed. But in real the code understands those characters as many ascii characters. So when I try to submit full form with these characters (āēīū’, and others) in submit.php IF statement error “Description should be between 500 and 2000 characters long!” shows up. So it’s because for example this special symbol ‘ is treated inserting this character before ‘. So it turns showing wrong count. I would like to enter only english characters. But with some special characters. For example ‘ this character is needed. But I need that it counts as 1 character not like 2 because of this slash.


      $(document).ready(function() {
        var text_max = 2000;
        $('#textarea_feedback').html(text_max + ' characters');

        $('#textarea').keyup(function() {
        var text_length = $('#textarea').val().length;
        var text_remaining = text_max - text_length;

        $('#textarea_feedback').html(text_remaining + ' characters');


    function sanitize($data) {
      return htmlentities(strip_tags(mysql_real_escape_string($data)));



    $sql = mysql_query("SELECT * FROM `table` ");

      while($row2 = mysql_fetch_array($sql)) {

        $description = $row2['description'];

     <?php if(strlen($description) >= 1000) { echo $description = substr($description, 0, 1000). '...'; ?>
      <a href="description.php?page=<?php echo $uid;?>">Read more</a>
    <?php } else { echo $description; } ?>


    <?php $description = sanitize($_POST['description']); 

      $sql2 = "INSERT INTO `table` (description)
        VALUES ('$description')";

    <form action="submit.php" method="post" enctype='multipart/form-data'>
      <span id="insert">Description</span><div id="textarea_feedback"></div><br>
      <textarea maxlength="2000" id="textarea" name="description" ><?php echo stripslashes($description); ?></textarea><br>
      <input type="submit" value="Submit" id="submit" name="submit" />

      if (isset($_POST['submit'])) {
        $con = mysql_connect("localhost","root","");
        if (!$con){
            exit("Can not connect: " . mysql_error());

      if ((strlen($description) < 500) or (strlen($description) > 2000)) {
      echo "<h1 class='top'>Description should be between 500 and 2000 characters long!</h1>";
      } else

Source: regex

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.