How To Handle a String Containing Apostrophes and Quotation Marks
How To Handle a String Containing Apostrophes and Quotation Marks
am 14.11.2007 05:00:39 von lucanos
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
Re: How To Handle a String Containing Apostrophes and Quotation Marks
am 14.11.2007 05:14:29 von Jerry Stuckle
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.
jstucklex@attglobal.net
==================
Re: How To Handle a String Containing Apostrophes and Quotation Marks
am 14.11.2007 05:26:31 von lucanos
On Nov 14, 3:14 pm, Jerry Stuckle wrote:
> 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
Re: How To Handle a String Containing Apostrophes and Quotation Marks
am 14.11.2007 05:52:43 von Jerry Stuckle
Lucanos wrote:
> On Nov 14, 3:14 pm, Jerry Stuckle wrote:
>> 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/language.types.string.php#langu age.types.string.syntax.heredoc
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Re: How To Handle a String Containing Apostrophes and Quotation Marks
am 14.11.2007 06:39:10 von lucanos
On Nov 14, 3:52 pm, Jerry Stuckle wrote:
> Lucanos wrote:
> > On Nov 14, 3:14 pm, Jerry Stuckle wrote:
> >> 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/language.types.string.php#langu age.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!