ignace Posted June 23, 2012 Share Posted June 23, 2012 Anybody here that can tell me why you need to write: file_put_contents('file.php', '<' . '?php ..'); document.write('<' + 'script>..</script>'); Instead of just writing <?php and <script ? It works without the concat, so why do I see it in some scripts? I tried Googling but it does not take symbols into account. Anyone of you guys know? Quote Link to comment Share on other sites More sharing options...
requinix Posted June 23, 2012 Share Posted June 23, 2012 For PHP you don't have to do that. For HTML I think only a "" has to be broken apart (because the JavaScript parsing comes after the browser has already determined the contents of the Quote Link to comment Share on other sites More sharing options...
ignace Posted June 23, 2012 Author Share Posted June 23, 2012 Well it works in both cases. At least when I tried it. HTML5 boilerplate has had it, I think. I have been wondering about this for years as to why you need to do that. Only recently did I have the courage to go and try to find an explanation on the internet. But nothing has yet turned up, implied knowledge it seems or many are just using it without knowing what it's for... Quote Link to comment Share on other sites More sharing options...
Mahngiel Posted June 23, 2012 Share Posted June 23, 2012 The string '</' is not allowed in JavaScript, because it could be misinterpreted as the end of the script tag (SGML short tag notation). Do '<'+'/script>' instead. Found that the other day researching something for somebody else. Can't take credit for it. http://stackoverflow.com/questions/1014203/best-way-to-use-googles-hosted-jquery-but-fall-back-to-my-hosted-library-on-go Underneath the accepted answer by boldewyn Quote Link to comment Share on other sites More sharing options...
Andy-H Posted June 25, 2012 Share Posted June 25, 2012 Perhaps syntax highlighting in the editor that was used to write the code messes up when it see's <?php (even when quoted as a string?) would be a crappy oversight on the SDK developers part but I can't really think of anything else? Quote Link to comment Share on other sites More sharing options...
Adam Posted June 26, 2012 Share Posted June 26, 2012 My attempt at explaining the JS issue to someone: http://forums.phpfreaks.com/index.php?topic=361547.0 Quote Link to comment Share on other sites More sharing options...
ignace Posted June 26, 2012 Author Share Posted June 26, 2012 For future reference: you can also use a backslash as demonstrated by h5bp @ https://github.com/h5bp/html5-boilerplate/blob/master/index.html: <script>window.jQuery || document.write('<script src="js/vendor/jquery-1.7.2.min.js"><\/script>')</script> Quote Link to comment Share on other sites More sharing options...
ignace Posted June 26, 2012 Author Share Posted June 26, 2012 The PHP part remains a mistery Quote Link to comment Share on other sites More sharing options...
requinix Posted June 26, 2012 Share Posted June 26, 2012 The PHP part remains a mistery I could see someone taking their "I have to do it with Quote Link to comment Share on other sites More sharing options...
spiderwell Posted June 27, 2012 Share Posted June 27, 2012 i have vague memories of doing this with old classic asp because it didnt like echoing out </script> as a complete word, so maybe its someone with old habits Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.