ragsr@ix.netcom.com Posted October 31, 2009 Share Posted October 31, 2009 QUESTION: Is is possible to embed a PHP variable in an HTML statement if the HTML is generated via an "echo" within PHP? If so, please give me a code example. BACKGROUND: I'm trying to get a Redirect working that passes a constant value and a variable value on to the href'd target using a query string. I know how to insert a PHP variable into an HTML statement if the HTML is run directly as HTML. For instance, the second example below, "HTML CODE", works fine. The first example, "PHP CODE", does not work. It runs and passes the absolute value "LOGINOK" correctly but the value for the variable $FBuseremailaddress does not resolve and a null is passed on to the target. PHP CODE: $redirectstring="<html><meta http-equiv='refresh' content='1;URL=http://apps.facebook.com/unitdummycanvas?FBlogin2=LOGINOK&FBlemail=<?php echo ($FBluseremailaddress) ; ?> '> <a href='http://apps.facebook.com/unitdummycanvas?FBlogin2=LOGINOK&FBlemail=<?php echo ($FBluseremailaddress) ; ?>' ></a></html> " ; echo "$redirectstring" ; (Note: url above is a dummy) HTML CODE: <html> <meta http-equiv='refresh' content='1;URL=http://apps.facebook.com/unitdummycanvas?FBlogin2=LOGINOK&FBlemail=<?php echo ($FBlemail) ; ?> '> <a href='http://apps.facebook.com/unitdummycanvas?FBlogin2=LOGINOK&FBlemail=<?php echo ($FBlemail) ; ?>'> </a> </html> Thanks for your help. Quote Link to comment Share on other sites More sharing options...
Mchl Posted October 31, 2009 Share Posted October 31, 2009 If your string is in double quotes, just put variable in it, and it will be evaluated: $redirectstring="<html><meta http-equiv='refresh' content='1;URL=http://apps.facebook.com/unitdummycanvas?FBlogin2=LOGINOK&FBlemail=$FBluseremailaddress'> <a href='http://apps.facebook.com/unitdummycanvas?FBlogin2=LOGINOK&FBlemail=$FBluseremailaddress' ></a></html> " ; echo "$redirectstring" ; Please use tags around code you paste on forums. It improves readability a lot. Quote Link to comment Share on other sites More sharing options...
ragsr@ix.netcom.com Posted October 31, 2009 Author Share Posted October 31, 2009 Mchl, If I understand you right, your suggestion is exactly what I'm doing and it doesn't work. It does the folloing..."It runs and passes the absolute value "LOGINOK" correctly but the value for the variable $FBuseremailaddress does not resolve and a null is passed on to the target." What am I missing??? Bob G. Quote Link to comment Share on other sites More sharing options...
Mchl Posted October 31, 2009 Share Posted October 31, 2009 This means $FBuseremailaddress is empty Quote Link to comment Share on other sites More sharing options...
ragsr@ix.netcom.com Posted October 31, 2009 Author Share Posted October 31, 2009 Mchl...the variable is not empty. I've verified that there is a value in place just before the redirect is executed. Since it works in pure HTML and does not work when it is echo'd within PHP, I thought that I may have to code the <?php echo $FBenduseremailaddress ; ?> somewhat differently. Quote Link to comment Share on other sites More sharing options...
Mchl Posted October 31, 2009 Share Posted October 31, 2009 Ok... so what var_dump($FBluseremailaddress) shows? Quote Link to comment Share on other sites More sharing options...
ragsr@ix.netcom.com Posted October 31, 2009 Author Share Posted October 31, 2009 Mchl, Try this simple test to see what I'm talking about. If I run this code I get no value between ...FBlemail= and ENDOFTESTSTRING when the second echo is executed. I should get EMAILADDRESS. TEST CODE: $FBluseremailaddress="EMAILADDRESS" ; echo "FBl: "."$FBluseremailaddress"."<br>" ; echo "ECHO: "."TESTSTRING=LOGINOK&FBlemail=<?php echo ($FBluseremailaddress) ; ?>ENDOFTESTSTRING" ; Quote Link to comment Share on other sites More sharing options...
Mchl Posted October 31, 2009 Share Posted October 31, 2009 Does the code I pasted above look like this? Quote Link to comment Share on other sites More sharing options...
ragsr@ix.netcom.com Posted October 31, 2009 Author Share Posted October 31, 2009 Mchl...I finally see the difference. I'll try it. Quote Link to comment Share on other sites More sharing options...
ragsr@ix.netcom.com Posted October 31, 2009 Author Share Posted October 31, 2009 Mchl....AWESOME!! Thanks for being so patient with me. I was stuck for a couple of days on this one. Your help is greatly appreciated. Thanks again. Cheers, Bob G. Quote Link to comment Share on other sites More sharing options...
Mchl Posted October 31, 2009 Share Posted October 31, 2009 Cool. I would just like to remind you: Please use tags around code you paste on forums. It improves readability a lot. Quote Link to comment Share on other sites More sharing options...
ragsr@ix.netcom.com Posted October 31, 2009 Author Share Posted October 31, 2009 Mchl...got the reminder. Will do. Cheers Quote Link to comment 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.