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

  • Home
  • SEARCH
  • 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 6973229
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:04:53+00:00 2026-05-27T17:04:53+00:00

Which characters do I need to escape on user input to a flatfile database?

  • 0

Which characters do I need to escape on user input to a flatfile database? I already have explicit testing against type, but am aware that code could be injected into the database or used to alter the queries.

So which characters must I escape before I store the user input?

Other security suggestions are welcome as I may have missed something.

After reading comments this is my function:

    private function cleanInput($input) {
        switch($this->_config->delimiter()) {
            case '\"';
            case '"';
            case '\\';
            case '\0';
                break;
            default;
                $input = addslashes($input);
        }               
        $output = preg_quote($input, $this->_config->delimiter());
        return $output;
    }
  • 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. Editorial Team
    Editorial Team
    2026-05-27T17:04:53+00:00Added an answer on May 27, 2026 at 5:04 pm

    What you need to escape depends on what you’re doing with the data. If you just dump data into a flatfile in this format:

    foo,bar,baz
    foo1,bar1,baz1
    

    Then obviously the , and newline character are significant characters in your storage format. Therefore you’ll need to escape any , or newline characters in the values themselves.

    There is also the question of how you’re inserting the data. If you just dump it using fwrite($fh, $data), there’s nothing to escape. If you’re using some SQL like frontend for your flatfile backend, you need to escape any values you may be concatenating into the SQL query to keep the SQL syntax valid.

    Escaping data is only necessary when you embed text strings in other strings, there are some characters that have a special meaning and you don’t want these special characters in the value strings to trigger any special action. In that case you need to escape any characters which may have a special meaning.

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

Sidebar

Related Questions

I have an NSString which has escape characters etc in it. I need to
I need a method in JavaScript to escape all characters which are not (
I have an NSString which is splitted into set of characters. I need to
I need to escape special characters in an invalid XML file which is about
I need to escape % characters in a string entered by the user -
Using PHP against a UTF-8 compliant database. Here's how input goes in. user types
I am writing a small app which I need to test with utf-8 characters
I would need to get a Regular Expression, which matches all Unicode control characters
I have a bunch of characters which are encoded in the form %XX%XX. How
my data includes arabic characters which looks like garbage in mysql but displays correctly

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.