#1
  1. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Mar 2008
    Posts
    761
    Rep Power
    40

    Ebdedding PHP inside Javascript


    nevermind
    Last edited by lelales; April 2nd, 2008 at 12:54 PM. Reason: fixed
  2. #2
  3. User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2005
    Location
    UK
    Posts
    471
    Rep Power
    76
    Is that nevermind as in dont bother answering or wud ur rather i answered the question in your title?

    You can't, php is loaded on the server before the user gets it and js is in the browser after the page has loaded on the users machine. You can only do so with ajax.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Mar 2008
    Posts
    761
    Rep Power
    40

    hi sephers 181


    Actually, you can embed PHP in JavaScript to produce dynamic JavaScript.

    Though I'm working out the bugs, you can visit this page: http://www.caillouette.com/RE_dynamic/index2.php

    Rollover the thumbnails. The PHP creates JavaScript on the fly, all in relation to a database.
  6. #4
  7. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,304
    Rep Power
    7173
    It is fundamentally impossible to embed PHP within javascript. Using PHP to create dynamic Javascript is not at all the same thing as embedding PHP in Javascript.

    Ajax doesn't count as embedding PHP in javascript either, since it's a completely separate HTTP request. Ajax can be used to make it look like PHP is embedded in the javascript but it isn't really and can't be because PHP and javascript are fundamentally different languages for fundamentally different purposes.

    Comments on this post

    • sephers181 agrees
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2008
    Posts
    96
    Rep Power
    13
    Originally Posted by E-Oreo
    It is fundamentally impossible to embed PHP within javascript. Using PHP to create dynamic Javascript is not at all the same thing as embedding PHP in Javascript.

    Ajax doesn't count as embedding PHP in javascript either, since it's a completely separate HTTP request. Ajax can be used to make it look like PHP is embedded in the javascript but it isn't really and can't be because PHP and javascript are fundamentally different languages for fundamentally different purposes.
    But you can create dynamic server side JS with a PHP file, that has a application/javascript content-type header in it. I assume that is what lelales is referring to.

IMN logo majestic logo threadwatch logo seochat tools logo