[email protected] 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. Link to comment https://forums.phpfreaks.com/topic/179759-solved-string-query-variable-in-php-echo-can-it-work/ 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. Link to comment https://forums.phpfreaks.com/topic/179759-solved-string-query-variable-in-php-echo-can-it-work/#findComment-948416 Share on other sites More sharing options...
[email protected] 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. Link to comment https://forums.phpfreaks.com/topic/179759-solved-string-query-variable-in-php-echo-can-it-work/#findComment-948420 Share on other sites More sharing options...
Mchl Posted October 31, 2009 Share Posted October 31, 2009 This means $FBuseremailaddress is empty Link to comment https://forums.phpfreaks.com/topic/179759-solved-string-query-variable-in-php-echo-can-it-work/#findComment-948421 Share on other sites More sharing options...
[email protected] 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. Link to comment https://forums.phpfreaks.com/topic/179759-solved-string-query-variable-in-php-echo-can-it-work/#findComment-948423 Share on other sites More sharing options...
Mchl Posted October 31, 2009 Share Posted October 31, 2009 Ok... so what var_dump($FBluseremailaddress) shows? Link to comment https://forums.phpfreaks.com/topic/179759-solved-string-query-variable-in-php-echo-can-it-work/#findComment-948426 Share on other sites More sharing options...
[email protected] 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" ; Link to comment https://forums.phpfreaks.com/topic/179759-solved-string-query-variable-in-php-echo-can-it-work/#findComment-948429 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? Link to comment https://forums.phpfreaks.com/topic/179759-solved-string-query-variable-in-php-echo-can-it-work/#findComment-948432 Share on other sites More sharing options...
[email protected] Posted October 31, 2009 Author Share Posted October 31, 2009 Mchl...I finally see the difference. I'll try it. Link to comment https://forums.phpfreaks.com/topic/179759-solved-string-query-variable-in-php-echo-can-it-work/#findComment-948433 Share on other sites More sharing options...
[email protected] 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. Link to comment https://forums.phpfreaks.com/topic/179759-solved-string-query-variable-in-php-echo-can-it-work/#findComment-948436 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. Link to comment https://forums.phpfreaks.com/topic/179759-solved-string-query-variable-in-php-echo-can-it-work/#findComment-948437 Share on other sites More sharing options...
[email protected] Posted October 31, 2009 Author Share Posted October 31, 2009 Mchl...got the reminder. Will do. Cheers Link to comment https://forums.phpfreaks.com/topic/179759-solved-string-query-variable-in-php-echo-can-it-work/#findComment-948440 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.