waynem Posted June 13, 2011 Share Posted June 13, 2011 Hello, I'll put me hands up if you can crack this… I have a php variable that is: $a= "<SCRIPT language=JavaScript>document.write(areCookiesEnabled())</script>"; And if I: Echo $a; I get True Which is perfect. However the value of $a is: not "true" its "<SCRIPT language=JavaScript>document.write(areCookiesEnabled())</script>" So if I try a: If ($a == 'true') { It doesn't work because: $a is '<SCRIPT language=JavaScript>document.write(areCookiesEnabled())</script>' not 'true' How do I extract the value from $a? So that $a will be 'true'?? Hope this makes sense if someone can shed some light i will email them a beer Quote Link to comment https://forums.phpfreaks.com/topic/239226-how-to-get-value-from-variable/ Share on other sites More sharing options...
monkeytooth Posted June 13, 2011 Share Posted June 13, 2011 PHP and JavaScript don't mix like that. In terms of page loading rendering etc.. PHP does its thing server side and renders everything before any initial output to the browsers. Where JavaScript loads there after when the page is done loading. So in order for you to pull off what you want to do is go the AJAX route, make a small javascript that detects the cookies like you already have define it as a var instead of writing it to the body of the document. then post it to a php file thats going to do whatever it is you wanna do based on if the result is true or false. Quote Link to comment https://forums.phpfreaks.com/topic/239226-how-to-get-value-from-variable/#findComment-1229025 Share on other sites More sharing options...
waynem Posted June 13, 2011 Author Share Posted June 13, 2011 Hello monkeytooth, and thank you for the reply. If i want to create a java if cookie=true { <script type="text/javascript" src="public/js/jquery.min.js"></script> } Is it possible to put a script within a script? Quote Link to comment https://forums.phpfreaks.com/topic/239226-how-to-get-value-from-variable/#findComment-1229034 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.