41 users online (1 members and 40 guests)  


  Results 1 to 5 of 5

Related

  1. how to stop javascript via another javascript    Forum: Javascript Forum
    Replies: 0
  2. Replies: 8
  3. Replies: 5
  4. Javascript / css    Forum: Javascript Forum
    Replies: 1
  5. JavaScript    Forum: Javascript Forum
    Replies: 2
  1. #1
    Dronae's Avatar
    New User

    Status
    Offline
    Join Date
    Apr 2004
    Posts
    1

    Javascript in PHP

    I'm trying to insert a counter into a PHP page using Javascript.

    The original code for the counter is:
    HTML Code:
    <script language="javascript">
    var data, p;
    var agt=navigator.userAgent.toLowerCase();
    p='http';
    if((location.href.substr(0,6)=='https:')||(location.href.substr(0,6)=='HTTPS:')) {p='https';} data = '&r=' + escape(document.referrer) + '&n=' + escape(navigator.userAgent) + '&p=' + escape(navigator.userAgent)
    if(navigator.userAgent.substring(0,1)>'3') {data = data + '&sd=' + screen.colorDepth + '&sw=' + escape(screen.width+ 'x'+screen.height)};
    document.write('<a href="http://www.ecounters.com" target="_blank" >');
    document.write('<img border=0 hspace=0 '+'vspace=0 src="http://www.ecounters.com/counter.php?i=310' + data + '"> </a>');
    </script>
    To put it in PHP:
    PHP Code:
    echo '
    <script language="javascript">
    var data, p;
    var agt=navigator.userAgent.toLowerCase();
    p='
    http';
    if((location.href.substr(0,6)=='
    https:')||(location.href.substr(0,6)=='HTTPS:')) {p='https';} data = '&r=' + escape(document.referrer) + '&n=' + escape(navigator.userAgent) + '&p=' + escape(navigator.userAgent)
    if(navigator.userAgent.substring(0,1)>'
    3') {data = data + '&sd=' + screen.colorDepth + '&sw=' + escape(screen.width+ 'x'+screen.height)};
    document.write('
    <a href="http://www.ecounters.com" target="_blank" >');
    document.write('
    <img border=0 hspace='+'vspace=0 src="http://www.ecounters.com/counter.php?i=310' + data + '"> </a>');
    </script>
    '

    However, I get
    Parse error: parse error, expecting `','' or `';'' on line 8,

    which is the '; line in the script.

    After replacing '; with `'," and `';" I still end up with the same error message.

    Any help in this would be appreciated. Thanks in advance.

  2. #2
    QuietDean's Avatar
    Administrator

    Status
    Offline
    Join Date
    Oct 2000
    Location
    Bournemouth, UK
    Posts
    2,662
    Hiya,

    replace the ' with \' , that should do it.
    If one of our members helps you, please click the icon to add to their reputation!
    No support via email or private message - use the forums!
    Before you ask, have you Searched?

  3. #3
    mozg's Avatar
    New User

    Status
    Offline
    Join Date
    Apr 2004
    Posts
    1
    Just put your code between tags {capture} {/capture}
    Isn't it?

  4. #4
    Nesper's Avatar
    New User

    Status
    Offline
    Join Date
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    9
    You could also simply close your php tags then write your js as you normally would and then open your php tags again.

    eg:
    PHP Code:
    <?php

    // some php code here

    //now close your php tag
    ?>

    <script language="javascript">
    var data, p;
    var agt=navigator.userAgent.toLowerCase();
    p='http';
    if((location.href.substr(0,6)=='https:')||(location.href.substr(0,6)=='HTTPS:')) {p='https';} data = '&r=' + escape(document.referrer) + '&n=' + escape(navigator.userAgent) + '&p=' + escape(navigator.userAgent)
    if(navigator.userAgent.substring(0,1)>'3') {data = data + '&sd=' + screen.colorDepth + '&sw=' + escape(screen.width+ 'x'+screen.height)};
    document.write('<a href="http://www.ecounters.com" target="_blank" >');
    document.write('<img border=0 hspace=0 '+'vspace=0 src="http://www.ecounters.com/counter.php?i=310' + data + '"> </a>');
    </script>

    <?php
    //now we reopen the php tags

    //put in somew more php code and finish off your page
    ?>
    This can even be done in the middle of php functions.

    Hope it helped some.

  5. #5
    blah's Avatar
    New User

    Status
    Offline
    Join Date
    Sep 2004
    Posts
    1
    HTML Code:
    _
    Last edited by blah; 09-22-2004 at 10:56 PM.



Tags for this Thread