Jump to content

Recommended Posts

Hey guys,

 

I am new here (and somewhat new to coding in general, though I am getting the hang of it). I searched php help forums on Google and ended up here. ANYWAY... I really hope you guys can help me out, I'd love to contribute to this forum every day :)

 

Okay, on to my question...

 

Is there any way that I can ECHO a variable into another variable? I don't mean like $var = $var2 (that would be pointless), I mean something like $var = echo $var2. Is there a function for that? The reason that I need to do this is...

 

My variable contains javascript, like so:

$url='http://www.esnips.com/nsdoc/'. $file .'<script type="text/javascript"> document.write("/?id=" + new Date().getTime() + "")</script>';

 

The javascript is to generate "id". I want to include that variable in another function like

include($url);

 

and similar situations without it literally showing the javascript. If I run the include command for this I get:

http://www.esnips.com/nsdoc/XXXXXXXXX/<script type="text/javascript"> document.write("/?id=" + new Date().getTime() + "")</script>

 

But if I echo it I get:

http://www.esnips.com/nsdoc/XXXXXXXXX/?id=XXXXXXXX

(which is how it should be)

 

So is there any way I can ECHO the variable into an include situation or another variable without it taking the javascript literally?

 

Thanks so much in advance.  :D

Link to comment
https://forums.phpfreaks.com/topic/90138-quick-php-question/
Share on other sites

Maybe I don't understand what you're trying to do but why are you using Javascript?

 

$url='http://www.esnips.com/nsdoc/'. $file .'?id=' . time();

 

 

I have to in order to generate the ID (it fetches functions from another file) -- any clue how to echo a variable in a variable, though?

Link to comment
https://forums.phpfreaks.com/topic/90138-quick-php-question/#findComment-462244
Share on other sites

What you're trying to do (and I may be wrong, but I'm pretty sure I'm not) is unfeasible, as PHP is a server-side language and JS is client-side.  Therefore, all of your PHP is parsed before there is any output to the browser, while JS is actually part of the output.  If all you're doing is getting the time, do what schilly recommended, as use the PHP function time().

 

Theo

Link to comment
https://forums.phpfreaks.com/topic/90138-quick-php-question/#findComment-462255
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.