473,396 Members | 1,998 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,396 software developers and data experts.

How To Handle a String Containing Apostrophes and Quotation Marks

Hey Guys,

Probably a simple question, but one I am struggling with all the same.
I know that in PHP you wrap a text string in apostrophes or quotations
- (examples $variable = 'this string' OR $variable = "that string" ).

What I am trying to figure is how to handle a string which contains
both apostrophes and quotations already. Is there a something like
CDATA is for XML?

Thanks
Luke

Nov 14 '07 #1
4 18477
Lucanos wrote:
Hey Guys,

Probably a simple question, but one I am struggling with all the same.
I know that in PHP you wrap a text string in apostrophes or quotations
- (examples $variable = 'this string' OR $variable = "that string" ).

What I am trying to figure is how to handle a string which contains
both apostrophes and quotations already. Is there a something like
CDATA is for XML?

Thanks
Luke

Escape them with backslashes, i.e.

echo 'It\'s a boy!";
echo "He said \"Here we go again!\"";

It's a boy!
He said "Here we go again!"

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Nov 14 '07 #2
On Nov 14, 3:14 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
Lucanos wrote:
Hey Guys,
Probably a simple question, but one I am struggling with all the same.
I know that in PHP you wrap a text string in apostrophes or quotations
- (examples $variable = 'this string' OR $variable = "that string" ).
What I am trying to figure is how to handle a string which contains
both apostrophes and quotations already. Is there a something like
CDATA is for XML?
Thanks
Luke

Escape them with backslashes, i.e.

echo 'It\'s a boy!";
echo "He said \"Here we go again!\"";

It's a boy!
He said "Here we go again!"

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================
Hi Jerry,

Thanks for the reply - I appreciate it.
The backslashing looks easy enough, but what if you are dealing with a
large chunk of text which contains both types of characters? I know I
could manually fo a "find-and-replace" to add backslashes, but is
there any other way?

Once again, I appreciate your help.

Luke

Nov 14 '07 #3
Lucanos wrote:
On Nov 14, 3:14 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
>Lucanos wrote:
>>Hey Guys,
Probably a simple question, but one I am struggling with all the same.
I know that in PHP you wrap a text string in apostrophes or quotations
- (examples $variable = 'this string' OR $variable = "that string" ).
What I am trying to figure is how to handle a string which contains
both apostrophes and quotations already. Is there a something like
CDATA is for XML?
Thanks
Luke
Escape them with backslashes, i.e.

echo 'It\'s a boy!";
echo "He said \"Here we go again!\"";

It's a boy!
He said "Here we go again!"

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================

Hi Jerry,

Thanks for the reply - I appreciate it.
The backslashing looks easy enough, but what if you are dealing with a
large chunk of text which contains both types of characters? I know I
could manually fo a "find-and-replace" to add backslashes, but is
there any other way?

Once again, I appreciate your help.

Luke

For large amounts of text, with or without quotes and apostrophes, try
the heredoc syntax:

http://www.php.net/manual/en/languag...syntax.heredoc

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Nov 14 '07 #4
On Nov 14, 3:52 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
Lucanos wrote:
On Nov 14, 3:14 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
Lucanos wrote:
Hey Guys,
Probably a simple question, but one I am struggling with all the same.
I know that in PHP you wrap a text string in apostrophes or quotations
- (examples $variable = 'this string' OR $variable = "that string" ).
What I am trying to figure is how to handle a string which contains
both apostrophes and quotations already. Is there a something like
CDATA is for XML?
Thanks
Luke
Escape them with backslashes, i.e.
echo 'It\'s a boy!";
echo "He said \"Here we go again!\"";
It's a boy!
He said "Here we go again!"
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================
Hi Jerry,
Thanks for the reply - I appreciate it.
The backslashing looks easy enough, but what if you are dealing with a
large chunk of text which contains both types of characters? I know I
could manually fo a "find-and-replace" to add backslashes, but is
there any other way?
Once again, I appreciate your help.
Luke

For large amounts of text, with or without quotes and apostrophes, try
the heredoc syntax:

http://www.php.net/manual/en/languag...language.types...

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================
Exactly what I was looking for - Many thanks Jerry!

Nov 14 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: new | last post by:
Just wonder how you guys handle the single quatation marks when you write the value of a text input into SQL server. Thanks! * * * Sent via DevBuilder http://www.devbuilder.org * * * Developer...
63
by: Tristan Miller | last post by:
Greetings. Do any popular browsers correctly support <q>, at least for Western languages? I've noticed that Mozilla uses the standard English double-quote character, ", regardless of the lang...
24
by: Sathyaish | last post by:
This one question is asked modally in most Microsoft interviews. I started to contemplate various implementations for it. This was what I got. #include <stdio.h> #include <stdlib.h> #include...
4
by: Andy Fish | last post by:
When using databinding, I have gotten into the habit of using single quotes (apostrophe) round attribute values rather than double quotes because this allows visual studio to work when there are...
4
by: | last post by:
Hi, How do I trim double quotation mark " in a string? Or, how do I match pattern if the string has double quotation mark already like "string"? Thanks in advance. Hugh
4
by: MooMaster | last post by:
After some google searching on the forum I couldn't find any topics that seemed to relate exactly to my problem, so hopefully someone can help me out... I'm running python 2.4.1 on a local Win2K...
4
by: Ryan | last post by:
Sometimes I have a user who will copy and paste something from Word and it includes a curly variation of an apostrophe. When this text is displayed back to the user at a later date (after pulling...
3
by: Ufit | last post by:
Simple,dumm question - how to include quotation marks in the string? F.ex. "Data Source=.\SQLEXPRESS;AttachDbFilename="C:\client data.mdf";Integrated Security=True;User Instance=True" I get syntax...
31
by: The Bicycling Guitarist | last post by:
Hi. For many years I have been using &quot; for double quotation marks in the HTML code, but the opening and closing quotation marks render the same in my browser. I'm considering going through and...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.