简体   繁体   中英

How to echo $username variable into a javascript

I was wondering if there is a way to display or echo a $username variable within a javascript function that display an html string. This is the original function:

    Plugin.prototype.counter = function() {
    if (this.s.counter) {
    $(this.s.appendCounterTo).append('<div id="counter"><span id="counter-current">' 
        + (parseInt(this.index, 10) + 1) + '</span> / <span id="counter-all">' 
        + this.$items.length 
        + '</span><a href="index.htm"><sig> JOHN SMITH </sig><img src="jOHN.png"></a></div>');
    }
};

I've tried inserting this:

    <?php $arrays = file_get_contents('username.txt'); echo $arrays;?>

Instead of JOHN SMITH , with and without quotes... Not working.

Any idea how to do such task?

Taking a wild guess here, it's possible your file is being called incorrectly.

This will specify the absolute path on the server.

<?=file_get_contents($_SERVER['DOCUMENT_ROOT'] . '/username.txt');?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM