c_martini Posted January 24, 2013 Share Posted January 24, 2013 First, forgive my lack of php knowledge, but I am a designer who has been tasked with some minor php work... * I have a php page with an iframe including a php form. * I have set a variable in the url of the iframe src attribute like so: <iframe src="mailForm.php?pageSubject=Fundraising"></iframe> * I need to output this variable within a declared variable value in the mailForm.php file: $subject = "Enquiry about $pageSubject" * I am able to echo the variable in the php page like this: <?php echo $_GET['pageSubject']; ?> How can I output that variable within the text string of $subject? Quote Link to comment https://forums.phpfreaks.com/topic/273611-using-a-_get-variable-in-a-variable-output-text-string/ Share on other sites More sharing options...
Love2c0de Posted January 24, 2013 Share Posted January 24, 2013 (edited) Try this: $subject = "Enquiry about {$pageSubject}"; echo $subject; Although it should print it without the curly braces? It's only single quotes which print the variable name rather than the value. Regards, L2c. Edited January 24, 2013 by Love2c0de Quote Link to comment https://forums.phpfreaks.com/topic/273611-using-a-_get-variable-in-a-variable-output-text-string/#findComment-1408072 Share on other sites More sharing options...
Love2c0de Posted January 24, 2013 Share Posted January 24, 2013 Oh sorry. Try this: $subject = "Enquiry number: {$_GET['pageSubject']}"; echo $subject; You may want to check and see if it is set first by doing this: if(isset($_GET['pageSubject'])) { $subject = "Enquiry number: {$_GET['pageSubject']}"; echo $subject; } else { //do something here. } Does this help? Regards, L2c. Quote Link to comment https://forums.phpfreaks.com/topic/273611-using-a-_get-variable-in-a-variable-output-text-string/#findComment-1408075 Share on other sites More sharing options...
c_martini Posted January 25, 2013 Author Share Posted January 25, 2013 Oh sorry. Try this: $subject = "Enquiry number: {$_GET['pageSubject']}"; echo $subject; You may want to check and see if it is set first by doing this: if(isset($_GET['pageSubject'])) { $subject = "Enquiry number: {$_GET['pageSubject']}"; echo $subject; } else { //do something here. } Does this help? Regards, L2c. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/273611-using-a-_get-variable-in-a-variable-output-text-string/#findComment-1408090 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.