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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T00:32:35+00:00 2026-06-11T00:32:35+00:00

Possible Duplicate: PHP: Convert special characters to HTML character codes I have a string

  • 0

Possible Duplicate:
PHP: Convert special characters to HTML character codes

I have a string column in DB which can have special character “&”.

This column value is used in options like:

<select onChange="display()">
echo "<option value='".$products."' </option>";

Added:
After this the HTML that is generated is correct:

<option value="{"varId":"2 & 4 wheel","month":"June"}"> two and four wheel </option>

And it is sent to PHP script. If the value of $products is “2 & 4 wheel” then in PHP all that I am getting is “2 ” and my query is failing.

I know this is because HTML can not handle special characters but how to get around this problem.

  • 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-06-11T00:32:37+00:00Added an answer on June 11, 2026 at 12:32 am

    HTML can handle “special characters”. Every language has its own “special characters”, and every language has its own rules for how to deal with them. HTML has HTML entities for this purpose. Before echoing any arbitrary values into HTML, always HTML-entity-encode them using htmlspecialchars.

    For more in-depth information about the topic, see The Great Escapism (Or: What You Need To Know To Work With Text Within Text).


    Regarding your update:

    <option value="{"varId":"2 & 4 wheel","month":"June"}"> two and four wheel </option>
    

    That is in no way correct HTML. The value contains ", and it’s entirely ambiguous which " are surrounding the value="..." attribute and which are part of the value. It needs to look like this:

    <option value="{&quot;varId&quot;:&quot;2 &amp; 4 wheel&quot;,&quot;month&quot;:&quot;June&quot;}"> two and four wheel </option>
    

    Just look at the difference in syntax highlighting here. And you’d get this with:

    $value = '{"varId":"2 & 4 wheel","month":"June"}';
    echo '<option value="' . htmlspecialchars($value); .'"> two and four wheel </option>';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: convert string to 2D array using php I have the string like
Possible Duplicate: Convert .doc to html in php I want to know how can
Possible Duplicate: Get first element of array Convert array to string php I have
Possible Duplicate: How can I convert ereg expressions to preg in PHP? I need
Possible Duplicate: PHP Get end string on url between / and / I have
Possible Duplicate: php loop through associative arrays i have a variable which prints an
Possible Duplicate: Convert HTML + CSS to PDF with PHP? how to convert a
Possible Duplicate: Convert one date format into another in PHP I've got a string
Possible Duplicate: Formating an SQL timestamp with PHP I have a column in my
Possible Duplicate of Convert jpg image to gif, png & bmp format using 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.