Jump to content

[SOLVED] String query variable in PHP echo - can it work??


ragsr@ix.netcom.com

Recommended Posts

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.

 

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.

 

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.

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.

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" ;

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.