wannabe_god Posted October 5, 2006 Share Posted October 5, 2006 I tried to combine javascript and php, and some one lines js commands work wellecho("<script>alert(\"test\")</script>");but now I have larger javascripts, and when I echo all the commands he doesn't work anymore ("error on the page" and he just doesnt works), and it is too hard to check the html output of the php script to check whats wrong, 'couse the echoëd code has no newlines in the source.... Could someone please help me out Link to comment Share on other sites More sharing options...
jesh Posted October 5, 2006 Share Posted October 5, 2006 Can you use <?php ?> in your code to separate the PHP from the javascript? Something like this: <html> <head> <script type="text/javascript">function myfunction(){ // normal javascript functionality to go here...} </script> </head> <body><?php // PHP functionality to go here...?> </body></html> Link to comment Share on other sites More sharing options...
aspnetguy Posted October 5, 2006 Share Posted October 5, 2006 you can use \n and \t in your echos to place new lines and tabs Link to comment Share on other sites More sharing options...
wannabe_god Posted October 5, 2006 Author Share Posted October 5, 2006 @sigh: i want to echo the javascript with php, not separate them @aspnetguy: like<?phpecho("<script>" . \n);echo("<alert(\"hey\")" . \n);echo("</script>" . \n);?>i suppose? Link to comment Share on other sites More sharing options...
aspnetguy Posted October 5, 2006 Share Posted October 5, 2006 @sigh: i want to echo the javascript with php, not separate them @aspnetguy: like<?phpecho("<script>" . \n);echo("<alert(\"hey\")" . \n);echo("</script>" . \n);?>i suppose?nope like this<?phpecho('<script>\n');echo('alert("hey")\n');echo('</script>\n');?> note: using single quotes lets you use double quotes inside without escaping them. Link to comment Share on other sites More sharing options...
DeathRay2K Posted October 5, 2006 Share Posted October 5, 2006 Or you could just use Heredoc.Like this: echo <<<script<script>alert("hey")</script>SCRIPT note that it should be < < < SCRIPT without the spaces, but for some reason the forum won't let me type that. Link to comment Share on other sites More sharing options...
reportingsjr Posted October 5, 2006 Share Posted October 5, 2006 I though it was <<<EOD?Yeah, it is:echo <<<EODTextEOD;Not script Link to comment Share on other sites More sharing options...
DeathRay2K Posted October 5, 2006 Share Posted October 5, 2006 I though it was <<<EOD?Yeah, it is:echo <<<EODTextEOD;Not scriptActually it doesn't matter what you use, it just has to alphanumeric + underscores and start with a letter.I just used SCRIPT to make it clear that it conatins javascript. Link to comment Share on other sites More sharing options...
reportingsjr Posted October 6, 2006 Share Posted October 6, 2006 Ive never seen that anywhere and in my php refrence book, by Mr. O`reilly it says to use that and never mentions script, and he put everything in that. Except half of the 2,500 functions , I will research it (provide a link plz?) Link to comment Share on other sites More sharing options...
DeathRay2K Posted October 7, 2006 Share Posted October 7, 2006 I have an O'Reilly reference book, and it doesn't give much notice to heredoc format at all, but at PHP.net there's a lot of info:http://ca.php.net/manual/en/language.types....syntax.heredoc Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now