SitePoint Sponsor

User Tag List

Results 1 to 15 of 15
  1. #1
    :) delemtri's Avatar
    Join Date
    Jun 2001
    Posts
    579
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP and JavaScript

    If I do this:

    <script src="blah.php"></script>

    Will "blah.php" be parsed for PHP or not?

  2. #2
    Node mutilating coot timnz's Avatar
    Join Date
    Feb 2001
    Location
    New Zealand
    Posts
    516
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm not sure, but you could try it. However, this works:
    Code:
    <script language="php"> 
    echo ("some editors (like FrontPage) don't like processing instructions");
    </script>
    http://www.php.net/manual/en/language.basic-syntax.php
    Oh no! the coots are eating my nodes!

  3. #3
    :) delemtri's Avatar
    Join Date
    Jun 2001
    Posts
    579
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Won't work. I need a way to include a PHP file, which would be parsed by my server, in other, possibly non-PHP pages.

    Any ideas?

  4. #4
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Delemtri,

    I am pretty sure you can't include a PHP file that gets parsed byu the server in page that is not itself parsed as PHP. Why can't you just parse all pages as PHP, or change your extensions around for the pages where you need to include that file?

    Timnz, whats with the signature?
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  5. #5
    :) delemtri's Avatar
    Join Date
    Jun 2001
    Posts
    579
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, the PHP file would be something that would be included on sites other than mine.

  6. #6
    Node mutilating coot timnz's Avatar
    Join Date
    Feb 2001
    Location
    New Zealand
    Posts
    516
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Timnz, whats with the signature?
    Believe it or not, you actually said that, so I thought I had better make the most of it As it wouldn't happen too often.
    Oh no! the coots are eating my nodes!

  7. #7
    :) delemtri's Avatar
    Join Date
    Jun 2001
    Posts
    579
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Would it work if I used:

    <script language="php" src="blah.php"></script>?

    Or am I just grabbing at straws?

  8. #8
    ********* wombat firepages's Avatar
    Join Date
    Jul 2000
    Location
    Perth Australia
    Posts
    1,717
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    assuming from the title that you want to include a .js file but with some dynamic content so

    <script language="javascript" src="js.php"></script>

    where js.php contains <?echo "alert(\"hello\");";?> etc etc

    works just fine

  9. #9
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In Perl you would actually tell the browser that the PHP script you are using is going to produce javascript by using the following line:

    print "Content-Type: application/x-javascript\n\n";

    Instead of:

    print "Content-type: text/html\n\n";


    You can then print content like this:

    print <<EOF;
    <!--
    document.write("$count");
    // -->
    EOF

    Can this be done with PHP?

    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature

  10. #10
    ********* wombat firepages's Avatar
    Join Date
    Jul 2000
    Location
    Perth Australia
    Posts
    1,717
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well you could, but there is no need, a script within a normal html page has no content type specified
    (for the script bit) - the sample above works in any script enabled browser.

  11. #11
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by firepages
    a script within a normal html page has no content type specified
    That is because PHP automatically specifies text/html is it not?

    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature

  12. #12
    ********* wombat firepages's Avatar
    Join Date
    Jul 2000
    Location
    Perth Australia
    Posts
    1,717
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if its a php generated page yes, what I meant was that in say a static HTML page with HTML and javascript - only textt/html is specified - the script works non the less.

    I am not saying that you can or 'should' not specify the content type I am saying that you do not need to.

  13. #13
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I get what your saying firepages I am just saying that this is a php generated page (the javascript code).

    The way you suggested is much simpler!

    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature

  14. #14
    :) delemtri's Avatar
    Join Date
    Jun 2001
    Posts
    579
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Echoing document.write() works! Thank you guys so much, you've been a real help!

  15. #15
    SitePoint Enthusiast nguip's Avatar
    Join Date
    Apr 2001
    Location
    Malaysia
    Posts
    95
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by firepages
    <script language="javascript" src="js.php"></script>

    where js.php contains <?echo "alert(\"hello\");";?> etc etc

    works just fine
    GREAT MAN ! Thanks.
    Ngu I.P.
    Web Developer


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •