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

Ask A Question

Stats

  • Questions 110k
  • Answers 110k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer See this list of browser safe fonts. It's Windows+Mac centric,… May 11, 2026 at 9:37 pm
  • Editorial Team
    Editorial Team added an answer No, there isn't any way. Try making all your exception… May 11, 2026 at 9:37 pm
  • Editorial Team
    Editorial Team added an answer As I found out, the problem is not with jetty.… May 11, 2026 at 9:37 pm

Related Questions

I have a desktop (winforms) application that uses a Firebird database as a data
Suppose I've got some Arch Linux installation which I'd like to distribute among students
When I'm creating a user for my web application, an SMTP email (using ASP.NET's
I've had this intermittent issue when using asp.net. My site is dynamically compiled. Sometimes

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.