Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jul 2008
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question php in javascript

    Whats up guys! I am trying to figure out how I can embed PHP codes in javascrip page but I cant find the way.can you halp me if there is any way

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,861
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Code:
    <script type="text/javascript">
    <?php
    echo "alert('hello')";
    ?>
    </script>
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    New to the CF scene
    Join Date
    Jul 2008
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    That one I know,but the thing is I have a page saved in .js extension and I want to embed php in it.is it going to work that way?

  • #4
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,861
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Save your script file with a php extension, say myfile.js.php and then add a php header at the beginning, like
    PHP Code:
    <?php
    header
    ('Content-type: application/javascript');
    ?>
    alert('<?php echo "hello";?>');
    <?php
    echo "alert('another hello :)')"
    ?>
    Now
    Code:
    <script type="text/javascript" src="myfile.js.php"></script>
    should work.
    Last edited by abduraooft; 08-01-2008 at 09:28 AM.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)


  •  

    Posting Permissions

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