For Programmers: Free Programming Magazines  


Home > Archive > PHP Language > October 2006 > PHP double quotes inside double quotes









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author PHP double quotes inside double quotes
MSB

2006-10-19, 6:56 pm

I am trying to figure out how to do double quotes inside double quotes

$newcode = str_replace("<a", "<a target=_blank", $newcode);

$newcode = str_replace("<a", "<a target="_blank"", $newcode);

the code works as is in the first example...but it screws up my validation
when it is parsed


Rik

2006-10-19, 9:56 pm

MSB wrote:
> I am trying to figure out how to do double quotes inside double quotes
>
> $newcode = str_replace("<a", "<a target=_blank", $newcode);
>
> $newcode = str_replace("<a", "<a target="_blank"", $newcode);
>
> the code works as is in the first example...but it screws up my
> validation when it is parsed


You could :
- quote with other quotes (so ' "bla"' will work), which I'd recommend.
- escape your quotes (so " \"bla\"")
- in large strigs, I'd recommend HEREDOC syntax.

Grtz,
--
Rik Wasmus


Wolfgang Forstmeier

2006-10-20, 7:57 am

Hi.

MSB wrote:
> I am trying to figure out how to do double quotes inside double quotes
>
> $newcode = str_replace("<a", "<a target=_blank", $newcode);
>
> $newcode = str_replace("<a", "<a target="_blank"", $newcode);


Just escape with ''.

This is explained here:
http://de2.php.net/types.string

$newcode = str_replace("<a", "<a target=\"_blank\"", $newcode);

>
> the code works as is in the first example...but it screws up my validation
> when it is parsed
>
>

Shelly

2006-10-21, 6:57 pm


"MSB" <ajhfdsa@adf.com> wrote in message
news:e45ef$45381d91$d8600654$7726@ALLTEL
.NET...
>I am trying to figure out how to do double quotes inside double quotes
>
> $newcode = str_replace("<a", "<a target=_blank", $newcode);
>
> $newcode = str_replace("<a", "<a target="_blank"", $newcode);
>
> the code works as is in the first example...but it screws up my validation
> when it is parsed
>


I bypass this problem, (and the quote character, "\"), by using single
quotes. This works for me:

$newcode = str_replace(' "<a", "<a target=_blank" ' , $newcode);

(Note: I have put a space between the single and double quotes here ONLY
for clarity for you to see what I mean. In the actual code I do not have
any space.

Shelly


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com