DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   PHP (http://www.daniweb.com/forums/forum17.html)
-   -   how to code single/double quotes inside the quotes. (http://www.daniweb.com/forums/thread23754.html)

rsaicrag May 17th, 2005 10:28 pm
how to code single/double quotes inside the quotes.
 
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>

sarahk May 18th, 2005 2:10 am
Re: how to code single/double quotes inside the quotes.
 
You can "escape" the quotes
<?
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>
 
";
 
?>

that's just putting a \ before them. Tells PHP to leave them alone.

farheen May 18th, 2005 3:53 pm
Re: how to code single/double quotes inside the quotes.
 
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.

sarahk May 18th, 2005 6:58 pm
Re: how to code single/double quotes inside the quotes.
 
Quote:

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

farheen May 18th, 2005 7:00 pm
Re: how to code single/double quotes inside the quotes.
 
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 ?

mediaphyte May 19th, 2005 12:11 am
Re: how to code single/double quotes inside the quotes.
 
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

fsn812 May 21st, 2005 10:36 pm
Re: how to code single/double quotes inside the quotes.
 
Quote:

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

farheen May 22nd, 2005 7:18 am
Re: how to code single/double quotes inside the quotes.
 
Now that i remember my beginning days, i have to agree.

rsaicrag May 27th, 2005 2:40 pm
Re: how to code single/double quotes inside the quotes.
 
Thanks ... sarahk

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

......
......


All times are GMT -4. The time now is 11:19 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC