Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 166425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T12:05:44+00:00 2026-05-11T12:05:44+00:00

Sometimes when a user is copying and pasting data into an input form we

  • 0

Sometimes when a user is copying and pasting data into an input form we get characters like the following:

didn’t,“ for beginning quotes and †for end quote, etc …

I use this routine to sanitize most input on web forms (I wrote it a while ago but am also looking for improvements):

function fnSanitizePost($data) //escapes,strips and trims all members of the post array {     if(is_array($data))     {     $areturn = array();     foreach($data as $skey=>$svalue)     {       $areturn[$skey] = fnSanitizePost($svalue);     }     return $areturn;   }   else     {       if(!is_numeric($data))         {             //with magic quotes on, the input gets escaped twice, which means that we have to strip those slashes. leaving data in your database with slashes in them, is a bad idea             if(get_magic_quotes_gpc()) //gets current configuration setting of magic quotes       {         $data = stripslahes($data);       }         $data = pg_escape_string($data); //escapes a string for insertion into the database         $data = strip_tags($data);  //strips HTML and PHP tags from a string       }         $data = trim($data);  //trims whitespace from beginning and end of a string       return $data;     } } 

I really want to avoid characters like I mention above from ever getting stored in the database, do I need to add some regex replacements in my sanitizing routine?

Thanks,

- Nicholas

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T12:05:44+00:00Added an answer on May 11, 2026 at 12:05 pm

    I finally came up with a routine for replacing these characters. It took parsing some of the problematic strings one character at a time and returning the octal value of each character. In doing so I learned that smart quote characters come back as sets of 3 octal values. Here is routine I used to parse the string:

    $str = 'string_with_smart_quote_chars';  $ilen = strlen($str); $sords = NULL;  echo '$str\n\n';  for($i=0; $i<$ilen; $i++) {     $sords .= ord(substr($str, $i, 1)).'  '; }  echo '$sords\n\n'; 

    Here are the str_replace() calls to ‘fix’ the string:

    $str = str_replace(chr(226).chr(128).chr(156), ''', $str); // start quote $str = str_replace(chr(226).chr(128).chr(157), ''', $str); // end quote $str = str_replace(chr(226).chr(128).chr(153), ''', $str); // for single quote 

    I am going to continue building up an array of these search/replacements which I am sure will continue to grow with the increasing use of these types of characters.

    I know that there are some canned routines for replacing these but I had no luck with any of them on the Solaris 10 platform that my scripts are running on.

    — Nicholas

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'd like to take user input (sometimes this will be large paragraphs) and generate
I sometimes use user data in php function header like this : header('Location :
Sometimes data is deleted from a database by a user which has been referred
Sometimes I m getting unicode errors like below in my django site when user
I have an each method that is run on some user-submitted data. Sometimes it
I'm creating a dynamic datatable full of input fields. Sometimes when user insert values
I get data from a textarea where a user has to enter a name
Sometimes in Salesforce tests you need to create User objects to run part of
I have a user of my application that sometimes when they run the application
I see that when connecting services to twitter/facebook, sometimes apps are storing the user

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.