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.

 

Link to comment
Share on other sites

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
Share on other sites

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
Share on other sites

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