ianco Posted September 24, 2009 Share Posted September 24, 2009 I want to display text when a tick box is ticked. This I can do BUT the text i want to display has a number of php tags(<?php echo $_POST["det"]; ?>). These wont display. Is it possible? Does the 'Some text' need to be withing brackets? The php is... if (isset($_POST['Submit1'])) { if (isset($_POST['ch1'])) { $ch1 = $_POST['ch1']; if ($ch1 = 'net') { $ch1 = 'Some text containing php tags'; } } } Thanks Ian Quote Link to comment https://forums.phpfreaks.com/topic/175402-php-within-php/ Share on other sites More sharing options...
PFMaBiSmAd Posted September 24, 2009 Share Posted September 24, 2009 Use htmlentities() with the 2nd parameter set to ENT_QUOTES The < and > of the php tags look like html tag delimiters and cause the php code to be treated as a html tag. Quote Link to comment https://forums.phpfreaks.com/topic/175402-php-within-php/#findComment-924293 Share on other sites More sharing options...
ianco Posted September 24, 2009 Author Share Posted September 24, 2009 Hmm... Sorry i'm a beginner at this. I want the php to output text. Where do i need to insert the htmlentities()? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/175402-php-within-php/#findComment-924302 Share on other sites More sharing options...
dad00 Posted September 24, 2009 Share Posted September 24, 2009 couldn't u just seperate it echo "<"."?"."php "."bla bla bla text "."?".">"; Quote Link to comment https://forums.phpfreaks.com/topic/175402-php-within-php/#findComment-924305 Share on other sites More sharing options...
mikesta707 Posted September 24, 2009 Share Posted September 24, 2009 assuming $ch1 is the text you want to output echo htmlentities($ch1); Quote Link to comment https://forums.phpfreaks.com/topic/175402-php-within-php/#findComment-924310 Share on other sites More sharing options...
PFMaBiSmAd Posted September 24, 2009 Share Posted September 24, 2009 @dad00 - The < and > of the php tags look like html tag delimiters and cause the php code to be treated as a html tag. If you literally output < and > using any method, the browser will treat them as the start and end of a html tag. You must convert them to html entities to so that they are not operated on by the bowser. Quote Link to comment https://forums.phpfreaks.com/topic/175402-php-within-php/#findComment-924312 Share on other sites More sharing options...
ianco Posted September 24, 2009 Author Share Posted September 24, 2009 @dad00 - The < and > of the php tags look like html tag delimiters and cause the php code to be treated as a html tag. If you literally output < and > using any method, the browser will treat them as the start and end of a html tag. You must convert them to html entities to so that they are not operated on by the bowser. I want the browser to read the php within the <> tags within the other php code though. if i change to < then it will appear as < Quote Link to comment https://forums.phpfreaks.com/topic/175402-php-within-php/#findComment-924321 Share on other sites More sharing options...
mikesta707 Posted September 24, 2009 Share Posted September 24, 2009 if you want the PHP to be parsed, then just echo it. But if you are parsing it anyways, why not just write the lines? there is also the eval function. $php = "<? echo \"My name is John\"; ?>"; eval($php); //output: //My name is John Quote Link to comment https://forums.phpfreaks.com/topic/175402-php-within-php/#findComment-924323 Share on other sites More sharing options...
ianco Posted September 24, 2009 Author Share Posted September 24, 2009 Cant get tis to work, where do i put the eval code? tried in a few places with no luck, just causes parsing errors? Sorry for being a pain Quote Link to comment https://forums.phpfreaks.com/topic/175402-php-within-php/#findComment-924347 Share on other sites More sharing options...
PFMaBiSmAd Posted September 24, 2009 Share Posted September 24, 2009 I want the browser to read the php within the <> tags Browser's don't read php code because php is a server side scripting language. Perhaps if you explained exactly what you are trying to accomplish with a real example of the code you want to use. Quote Link to comment https://forums.phpfreaks.com/topic/175402-php-within-php/#findComment-924352 Share on other sites More sharing options...
PFMaBiSmAd Posted September 24, 2009 Share Posted September 24, 2009 if i change to < then it will appear as < No. It won't. At least try something first. Quote Link to comment https://forums.phpfreaks.com/topic/175402-php-within-php/#findComment-924354 Share on other sites More sharing options...
ianco Posted September 24, 2009 Author Share Posted September 24, 2009 ok heres the code i have on my php page: (on the first checkbox has been defined so far) <?PHP $ch1 = 'unchecked'; $ch2 = 'unchecked'; $ch3 = 'unchecked'; $ch4 = 'unchecked'; $ch5 = 'unchecked'; if (isset($_POST['Submit1'])) { if (isset($_POST['ch1'])) { $ch1 = $_POST['ch1']; if ($ch1 = 'net') { $ch1 = '{<UL><br> <LI><br> <a href=<?php echo $_POST["num"]; ?>.pdf><?php echo $_POST["det"]; ?></a><br> </LI><br> <UL><br> <LI>(PDF format, <!-- #config SIZEFMT = "ABBREV" --><!--#fsize file="<?php echo $_POST["num"]; ?>.pdf"--> KB)</LI><br> </UL><br> </UL><br>}'; } } if (isset($_POST['ch2'])) { $ch2 = $_POST['ch2']; if ($ch2 = 'word') { $ch2 = 'checked'; } } if (isset($_POST['ch3'])) { $ch3 = $_POST['ch3']; if ($ch3 = 'excel') { $ch3 = 'checked'; } } if (isset($_POST['ch4'])) { $ch4 = $_POST['ch4']; if ($ch4 = 'web') { $ch4 = 'checked'; } } if (isset($_POST['ch5'])) { $ch5 = $_POST['ch5']; if ($ch5 = 'php') { $ch5 = 'checked'; } } } ?> <?PHP print $ch1; ?><br> <?PHP print $ch2; ?><br> <?PHP print $ch3; ?><br> <?PHP print $ch4; ?><br> <?PHP print $ch5; ?><br> ----------- and the html form <FORM NAME ="form1" METHOD ="POST" ACTION ="checkBoxes.php"> <INPUT TYPE = "Submit" Name = "Submit1" VALUE = "Choose your books"><br> Journal: <br> <select name="jou"> <option value="Journal of Materials Chemistry">Journal of Materials Chemistry</option> <option value="Soft Matter">Soft Matter</option> <option value="Polymer Chemistry">Polymer Chemistry</option> <option value="Nanoscale">Nanoscale</option> <option value="Physical Chemistry Chemical Physics">PCCP</option> <option value="CrystEngComm">CrystEngComm</option> <option value="Dalton Transactions">Dalton</option> <option value="Organic and Biomolecular Chemistry">OBC</option> </select> <br> Number: <br><input type="text" name="num" /><br> Details: <br><input type="text" name="det" /><br> Crystal structure data(txt): <br><input type="text" name="dettxt" /><br> Crystal structure data(cif): <br><input type="text" name="detcif" /><br> <Input type = 'Checkbox' Name ='ch1' value ="net" <?PHP print $ch1; ?> >Visual Basic .NET <P> <Input type = 'Checkbox' Name ='ch2' value="word" <?PHP print $ch2; ?> >Microsoft Word <P> <Input type = 'Checkbox' Name ='ch3' value="excel" <?PHP print $ch3; ?> >Microsoft Excel<br> <P> <Input type = 'Checkbox' Name ='ch4' value="web" <?PHP print $ch4; ?> >Web Design<br> <P> <Input type = 'Checkbox' Name ='ch5' value="php" <?PHP print $ch5; ?> >PHP for the Beginner<br> <P> </FORM> Quote Link to comment https://forums.phpfreaks.com/topic/175402-php-within-php/#findComment-924363 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.