| | |||||
| ||||||||
| Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics. |
![]() |
| | LinkBack | Thread Tools |
| | THREAD STARTER #1 (permalink) |
| Senior Member Join Date: Oct 2006 Location: http://akshayjain.org
Posts: 2,817
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | Javascript and php confusion hello i am here once again with my problems i have a php variable containing a URL -- $url what i want to do is to open a new window opening the URL specified in $url here is my code to generate a new window Code: echo '<SCRIPT LANGUAGE="JavaScript"><!-- Begin
window.open ("$url")
// End --></script>'; ????: NamePros.com http://www.namepros.com/programming/333460-javascript-and-php-confusion.html i have tried variation such as \"$url"\ but this give me some ASCII error please guide me on where i am going wrong |
| |
| | #2 (permalink) |
| NamePros Regular Join Date: Jul 2006
Posts: 333
![]() ![]() ![]() ![]() ![]() | It is not a very elegant solution, but must work: PHP Code: |
| |
| | #3 (permalink) |
| NamePros Expert Join Date: Nov 2003 Location: Scotland
Posts: 5,074
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | The reason it does not work is because the variable is in single quotes. Variables in sibngle quotes are treated as strings. To have them evaluated properly use double quotes or as klstrphnky suggests use concatenation (my favourite of the 2 methods) |
| |
| | #4 (permalink) |
| New Member Join Date: Mar 2007
Posts: 16
![]() | Since javascript can use either single or double quotes, you just put the string together like this ????: NamePros.com http://www.namepros.com/showthread.php?t=333460 PHP Code: effectively you are concatenating 3 strings and this would be equivalent (easier to understand maybe) PHP Code:
Last edited by samuofm; 05-30-2007 at 01:22 PM.
|
| |
| | #5 (permalink) |
| Buy my domains. Join Date: Feb 2006
Posts: 2,792
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | If you're going to use double quotes, you can do PHP Code: |
| |
| | #7 (permalink) | ||||
| NamePros Regular Join Date: May 2004 Location: NYC
Posts: 236
![]() ![]() ![]() |
| ||||
| |
| | #10 (permalink) | ||||
| New Member Join Date: Mar 2007
Posts: 16
![]() |
For example, here is some embedded php I wrote that makes use of nested ifs and it begins to become difficult to read. PHP Code: that's fairly hard to read with just two levels, and if I replaced those inner echoes with embedded php it would be even more challenging. | ||||
| |