PHP double quotes inside double quotes

This is a discussion on PHP double quotes inside double quotes within the alt.comp.lang.php forums, part of the PHP Programming Forums category; I am trying to figure out how to do double quotes inside double quotes $newcode = str_replace("<a", &...


Go Back   Usenet Forums > PHP Programming Forums > alt.comp.lang.php

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 10-20-2006
MSB
 
Posts: n/a
Default PHP double quotes inside double quotes

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


Reply With Quote
  #2 (permalink)  
Old 10-20-2006
Rik
 
Posts: n/a
Default Re: PHP double quotes inside double quotes

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


Reply With Quote
  #3 (permalink)  
Old 10-20-2006
Wolfgang Forstmeier
 
Posts: n/a
Default Re: PHP double quotes inside double quotes

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
>
>

Reply With Quote
  #4 (permalink)  
Old 10-21-2006
Shelly
 
Posts: n/a
Default Re: PHP double quotes inside double quotes


"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


Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 11:28 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0