PHP include in a Java Script

Discussion in 'PHP' started by aquasonic, May 2, 2007.

  1. #1
    Not sure if this should be in Java or PHP... but

    I have a couple of java scripts (a scrolling banner and a news ticker) both written in java script - but I want to be able to change the text on both of them using a PHP inclue - but when I try and do it - it just messes up the java script!

    I think it's because I'm using
    <?php include 'text.txt'; ?>
    PHP:
    But the apostrophes cause the java script to end the line... so if I change the apostrophes to quote marks... I get the same problem.

    Would it be better to perhaps put
    <?php echo $contents ?>
    PHP:

    and then have
    
    <?php
    $file = "text.txt";
    
    $contents = file_get_contents($file);
    
    ?>
    PHP:

    Somewhere else in the script - or would this not work?
     
    aquasonic, May 2, 2007 IP
  2. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #2
    post the script, dont like guessing games.....
     
    krakjoe, May 2, 2007 IP
  3. aquasonic

    aquasonic Well-Known Member

    Messages:
    90
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    115
    #3
    Okay, I'll post it up in sometime in the next couple of days... just on my way out right now.
     
    aquasonic, May 2, 2007 IP
  4. Subikar

    Subikar Active Member

    Messages:
    241
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #4
    Why you are calling javascript files from php it is better to cal through javascript.
     
    Subikar, May 2, 2007 IP
  5. aquasonic

    aquasonic Well-Known Member

    Messages:
    90
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    115
    #5
    Right - all sorted now... I was right... in my first post.

    I'm not sure what you mean by "Why you are calling javascript files from php it is better to cal through javascript."

    I'm not calling javascripts from php... I have javascripts in a php page and I want to call text documents within the java script... but by using file_get_contents and then using the echo to display them... I get over all y problems!

    I was having a stupid moment!
     
    aquasonic, May 3, 2007 IP