how to code single/double quotes inside the quotes.

Reply

Join Date: May 2005
Posts: 5
Reputation: rsaicrag is an unknown quantity at this point 
Solved Threads: 0
rsaicrag rsaicrag is offline Offline
Newbie Poster

how to code single/double quotes inside the quotes.

 
0
  #1
May 17th, 2005
Below is my code. The problem is on the 'javascript:ViewPage(article_1.html)'; How to code the quote inside the ViewPage function since im using the
echo "....." ;

<?
echo "
<script language='javascript'>
function ViewPage(url)
{ OpenWin = this.open(url, 'CtrlWindow', 'toolbar=yes,menubar=yes,location=no,scrollbars=yes,resizable=yes');
}
</script>

<tr><td><a href='javascript:ViewPage(article_1.html)';>Article1</a></td><tr>

";

?>

it should be

<a href="javascript:ViewPage('article_1.html')";>Article1</a>
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 138
Reputation: sarahk is an unknown quantity at this point 
Solved Threads: 1
sarahk's Avatar
sarahk sarahk is offline Offline
Junior Poster

Re: how to code single/double quotes inside the quotes.

 
0
  #2
May 18th, 2005
You can "escape" the quotes
  1. <?
  2. echo "
  3. <script language='javascript'>
  4. function ViewPage(url)
  5. { OpenWin = this.open(url, 'CtrlWindow', 'toolbar=yes,menubar=yes,location=no,scrollbars=yes,resizable=yes');
  6. }
  7. </script>
  8.  
  9. <tr><td><a href='javascript:ViewPage(\"article_1.html\")';>Article1</a></td><tr>
  10.  
  11. ";
  12.  
  13. ?>

that's just putting a \ before them. Tells PHP to leave them alone.
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 6
Reputation: farheen is an unknown quantity at this point 
Solved Threads: 0
farheen farheen is offline Offline
Newbie Poster

Re: how to code single/double quotes inside the quotes.

 
0
  #3
May 18th, 2005
Two important things:

1. You can enclose single quotes within double quotes WITHOUT escaping them and vice versa.

2. You should echo each line inidivdually.
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 138
Reputation: sarahk is an unknown quantity at this point 
Solved Threads: 1
sarahk's Avatar
sarahk sarahk is offline Offline
Junior Poster

Re: how to code single/double quotes inside the quotes.

 
0
  #4
May 18th, 2005
Originally Posted by farheen
2. You should echo each line inidivdually.
I disagree. I believe you should be building up a string of code and echo out less frequently.

For instance, lets say I have a function called getTable() I would expect it to return me a string of html formatted code for a table of data. I would then be able to call it with

echo getTable($result);

this will make the code faster and more modular. It probably takes us way beyond the original post but...

buried deep within my site I have some info on coding standards which also covers this.

Sarah
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 6
Reputation: farheen is an unknown quantity at this point 
Solved Threads: 0
farheen farheen is offline Offline
Newbie Poster

Re: how to code single/double quotes inside the quotes.

 
0
  #5
May 18th, 2005
I don't disagree with you, but how exactly would you do what you are talking about with the code provided by the original poster ?
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 19
Reputation: mediaphyte is an unknown quantity at this point 
Solved Threads: 0
mediaphyte mediaphyte is offline Offline
Newbie Poster

Re: how to code single/double quotes inside the quotes.

 
0
  #6
May 19th, 2005
actually.... i would do it like this (use straight html when you can... its quicker):

<? // does anything really need to be here? ?>
<script language="javascript">
function ViewPage(url)
{ OpenWin = this.open(url, 'CtrlWindow', 'toolbar=yes,menubar=yes,location=no,scrollbars=yes,resizable=yes');
}
</script>
<tr><td><a href="javascript:ViewPage('article_1.html');">Article1</a></td><tr>

otherwise.... echo 'a bunch of '.$stuff.' here';
or... echo "whatever you $want";
escaping works, but makes it a pain to move chunks of html out of <?php?> sections

good luck mediaphyte.com
Reply With Quote Quick reply to this message  
Join Date: Jan 2004
Posts: 93
Reputation: fsn812 is an unknown quantity at this point 
Solved Threads: 1
fsn812's Avatar
fsn812 fsn812 is offline Offline
Junior Poster in Training

Re: how to code single/double quotes inside the quotes.

 
0
  #7
May 21st, 2005
Originally Posted by mediaphyte
actually.... i would do it like this (use straight html when you can... its quicker):

<? // does anything really need to be here? ?>
<script language="javascript">
function ViewPage(url)
{ OpenWin = this.open(url, 'CtrlWindow', 'toolbar=yes,menubar=yes,location=no,scrollbars=yes,resizable=yes');
}
</script>
<tr><td><a href="javascript:ViewPage('article_1.html');">Article1</a></td><tr>

otherwise.... echo 'a bunch of '.$stuff.' here';
or... echo "whatever you $want";
escaping works, but makes it a pain to move chunks of html out of <?php?> sections

good luck mediaphyte.com
If a person is just getting started, I would point them in this direction. As their scripts/programs require more modularity and more code in general, it's always better to point them in the class/function direction. It's not too difficult to learn and it will provide better coding standards all around for the developer.

PHP4 OO: http://us2.php.net/oop/

PHP5 OO: http://us3.php.net/zend-engine-2.php
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 6
Reputation: farheen is an unknown quantity at this point 
Solved Threads: 0
farheen farheen is offline Offline
Newbie Poster

Re: how to code single/double quotes inside the quotes.

 
0
  #8
May 22nd, 2005
Now that i remember my beginning days, i have to agree.
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 5
Reputation: rsaicrag is an unknown quantity at this point 
Solved Threads: 0
rsaicrag rsaicrag is offline Offline
Newbie Poster

Re: how to code single/double quotes inside the quotes.

 
0
  #9
May 27th, 2005
Thanks ... sarahk

It works now...using this
.....
{
print ...\" ... \" ..... ;
}

......
......
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum


Views: 12132 | Replies: 8
Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC