473,395 Members | 1,456 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Escaping double quotes when displaying text

Claus Mygind
571 512MB
I have an array value of let's say

20" below grade

or I might have a value like

8' above grade

Because the value property is delimited with ", the following code cuts off the quote and trailing text when streamed out like this

Expand|Select|Wrap|Line Numbers
  1. <td><input type="text" name="Description" value="<?php echo $thisValue; ?>"></td>
  2.  
Of course I could just change it to single quotes and I would be ok until the user types in the second option.

Perhaps this is a HTML question, but how can I escape the double quote so it will properly stream out?

I tried escaping the the double quote with the \ as in "20\" below grade", but that just outputs 20\.

any suggested help would be appreciated.
Sep 24 '12 #1

✓ answered by Claus Mygind

Ok I get it now

http://php.net/manual/en/function.htmlspecialchars.php

this fixes the problem as in
Expand|Select|Wrap|Line Numbers
  1. <td><input type="text" name="Description" value='<?php echo htmlspecialchars ( $thisValue); ?>></td>

6 2558
Claus Mygind
571 512MB
Ok I get it now

http://php.net/manual/en/function.htmlspecialchars.php

this fixes the problem as in
Expand|Select|Wrap|Line Numbers
  1. <td><input type="text" name="Description" value='<?php echo htmlspecialchars ( $thisValue); ?>></td>
Sep 24 '12 #2
Dormilich
8,658 Expert Mod 8TB
I might add that there are special characters for minute (prime, U+2032) and second (double prime, U+2033), which hardly anyone knows they exist.

PS. there is a nice graphic in the german wiki that shows the differences between prime, typographical & straight apostrophe and the acute accent.
Sep 26 '12 #3
Claus Mygind
571 512MB
Thanks for that insight. I sure hope they don't use any of those characters like ` and ~
Oct 1 '12 #4
Hi,
Please check the str_replace function too for this issue.
http://php.net/manual/en/function.str-replace.php

I hope this is helpful for you.
Dec 20 '12 #5
Claus Mygind
571 512MB
Hi,
Please check the str_replace function too for this issue.
http://php.net/manual/en/function.str-replace.php

I hope this is helpful for you.
While you can do as you suggest, this is really a poor option and requires additional coding (see both my question and my own response to the question). By replacing the double quote you then also have to replace when retrieving the information.

Keep in mind the conflict is only because the double qoute is serving double duty as the wrapper for the content as well as being part of the content. And the wrapper is discarded when the content is stored in the data table, so why change the content for the sake of the temporary wrapper. Escaping the character instead of replacing it let's you preserve the use of the temporary wrapper without altering the content. That is to say it is being done behind the scenes for the programmer. Just like the wrapper is a temporary use item, so is the escaping. Escaping is a temporary replacing that is reversed once the content has been received by the data server. Therefore requiring less code and the need to reinvent the wheel.
Dec 21 '12 #6
Atli
5,058 Expert 4TB
I always preferred htmlentities over htmlspecialchars myself, because it encodes all characters that have a corresponding HTML entity, rather than just those 5 special chars. It may not really be an issue on 99% of HTML pages (it'll matter more on XML/XHTML pages), but it's not like it's costing any extra effort or measurable performance.

Why not go all the way, when it's no more difficult than only doing as little as possible?
Dec 21 '12 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: swtwllm | last post by:
I have been searching for an escape character or a way of escaping double quotes that are actually in a string that I am using in the contains predicate. Here is an example select * from...
24
by: deko | last post by:
I'm trying to log error messages and sometimes (no telling when or where) the message contains a string with double quotes. Is there a way get the query to insert the string with the double...
16
by: Charles Law | last post by:
I have a string similar to the following: " MyString 40 "Hello world" all " It contains white space that may be spaces or tabs, or a combination, and I want to produce an array...
1
by: Joe | last post by:
I want to bind a textbox to a field which is a double. If this field has not yet been set I would like to display a text value. Is there a way to override the display text when value ==...
0
by: arjun.arasu | last post by:
Hi, Need some help, everytime i import a text file, the driver(connCSV.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" _ & path & ";Extended Properties='text;HDR=YES;FMT=CSV'") takes away...
1
by: desi.american | last post by:
I have a dynamically generates ASPX page with tables and data. Depending on user selection, the same page can be viewed as a simple web page (rendered in HTML) or as an excel spreadsheet. If the...
15
by: bill | last post by:
I am trying to write clean code but keep having trouble deciding when to quote an array index and when not to. sometimes when I quote an array index inside of double quotes I get an error about...
2
by: Denise | last post by:
Front end is Access 2002, back end is linked Oracle tables. My users need to describe things in feet and inches and want to use the standard ' and " abbrevations. On a testing form I go to a...
11
by: tfurubay | last post by:
Hi, I am developing a DB that imports a CSV file from a commerce site. The file is a CSV file with double quotes to identify text. In this file, there is a memo field where people occassionally...
2
by: Dragomir | last post by:
Hi, I'm using a flag to try and not include text for parsing in double quotes. When trying to use flag for comments it works but it doesn't with the double quotes... Can you tell me why it didn't...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.