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 6091619
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:20:56+00:00 2026-05-23T12:20:56+00:00

I’m still new to String Processing in PHP. Below is a diagram of what

  • 0

I’m still new to String Processing in PHP. Below is a diagram of what I am currently doing. Ultimately, I would like to get a generic methodology for handling strings in the below scenarios. Note that the text tends to be a lot of math symbols and code syntax in this scenario.

The strings and integer are input via a standard HTML-based form (I forgot to mention that in the diagram).

Step A currently uses: mysql_real_escape_string(input);

Step B currently uses:

  • htmlentities($string2)
  • nothing for $string1
  • nothing for the integer

Questions:

  1. Regarding MySQL injection, is mysql_real_escape_string sufficient to guard against this?
  2. I still need to finish processing the output for String1. Note how the text is actually used in two different places: HTML and Canvas. htmlentities at step B would make code syntax appear properly on the HTML5 Canvas but not in the HTML. Vice-versa for leaving it out (HTML syntax breaks the Page). Is there a JavaScript function that is identical to PHP’s htmlentities?
  3. int form should be validated to make sure it is an int.
  4. String2 ouputs “null” to the HTML when I use this character (‘–’) which is not the standard minus-sign character (‘-‘).
  5. Magic Quotes is turned off. However, if I run the script on a server with it enabled, I need a short script that goes: IF(magic quotes is enabled){turn off magic quotes}.
  6. What did I forget in regard to form validation?

If my approach is totally wrong, set me straight and help me get this straightened out once and for all. You can describe your solution in terms of A, B, C, D and E if you think that is helpful. Thanks in advance.

String Processing Diagram

  • 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-23T12:20:57+00:00Added an answer on May 23, 2026 at 12:20 pm
    1. mysql_real_escape_string() will properly escape your code
    2. (A) On the JavaScript end, jQuery’s .text() method will properly escape code before outputting it to the page. (B) Check out PHP.js. It’s a JavaScript library that replicates PHP functionality, and includes htmlentities() and htmlspecialchars(). http://phpjs.org/
    3. As for the integer, you can use the ctype_digits() function to ensure that it is a numeric value; and you can also use some form of type hinting: $int = (int) $int;.
    4. I agree with the gentleman who recommended trying htmlspecialchars().
    5. Try to keep magic quotes off. It’s a horrible feature, and will be removed in a future release of PHP. If you need to include protection against magic quotes, try something similar to the code below. (see bottom of post)
    6. It’s hard to say without seeing your code, but it seems like you are on the right track.

    –

    if (function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc()) {
        $func = function(&$val, $key) {
            if (!is_numeric($val)) {
                $val = stripslashes($val);
            }
        };
    
        array_walk_recursive($_GET, $func);
        array_walk_recursive($_POST, $func);
        array_walk_recursive($_COOKIE, $func);
    
        unset($func);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to count the length of a string with PHP. The string
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I want use html5's new tag to play a wav file (currently only supported
Does anyone know how can I replace this 2 symbol below from the string
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,

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.