cesarcesar Posted August 10, 2008 Share Posted August 10, 2008 I need to show PHP and HTML code inside of a textarea for people to copy out into their own site. I can get code to work correct without PHP code in it like htmlspecialchars("<iframe src =\"http://www.sitename.com/app/score.php?quiz_id=".$_SESSION['action']['quiz_id']."&uid=0\" width=\"480\" height=\"925\" scrolling=\"no\" frameborder=\"0\" marginheight=\"0\" marginwidth=\"0\"></iframe>".$show_commander, ENT_QUOTES); But when adding PHP code into it its all FUBAR'd and throws a "Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /hsphere/local/home/santccom/sitename/app/step8.php on line 123 " error. This is my f'd code <?= htmlspecialchars("<? if($_GET['proxy']){ $param = 'field_name='.$_GET[field_name].'&proxy=1'; }else{ $param = 'quiz_id='.$_SESSION[action][quiz_id].'&uid=0'; } ?>".$show_commander, ENT_QUOTES); echo'<iframe src=\"http://www.sitename.com/app/score.php?$param\" width=\"480\" height=\"925\" scrolling=\"no\" frameborder=\"0\" marginheight=\"0\" marginwidth=\"0\"></iframe>'; ?> What i need is for something to look exactly similar to the following on screen inside of my textarea. <? if($_GET['proxy']){ $param = "field_name=".$_GET['field_name']."&proxy=1"; }else{ $param = "quiz_id=119&uid=0"; } echo"<iframe src=\"http://www.sitename.com/app/score.php?$param\" width=\"480\" height=\"925\" scrolling=\"no\" frameborder=\"0\" marginheight=\"0\" marginwidth=\"0\"></iframe>"; ?> Where am i going wrong? Thanks for the help. Quote Link to comment https://forums.phpfreaks.com/topic/119064-outputing-php-tags-in-a-textarea/ Share on other sites More sharing options...
papaface Posted August 10, 2008 Share Posted August 10, 2008 Try http://uk2.php.net/htmlentities instead of htmlspecialchars() Quote Link to comment https://forums.phpfreaks.com/topic/119064-outputing-php-tags-in-a-textarea/#findComment-613089 Share on other sites More sharing options...
cesarcesar Posted August 10, 2008 Author Share Posted August 10, 2008 trying... getting same error. Quote Link to comment https://forums.phpfreaks.com/topic/119064-outputing-php-tags-in-a-textarea/#findComment-613094 Share on other sites More sharing options...
cesarcesar Posted August 10, 2008 Author Share Posted August 10, 2008 ok i got the result i wanted, but i thinks is very dirty. I'm going with this way for now, but im still open for suggestions on the "correct" way to do it. <?= htmlspecialchars("<?php", ENT_QUOTES); ?> if($_GET['proxy']){ $param = 'field_name='.$_GET[field_name].'&question_num='.$_GET[question_num].'&quiz_id='.$_GET[quiz_id].'&score_id='.$_GET[score_id].'&field_value='.$_GET[field_value].'&proxy=1'; }else{ $param = '<?= htmlspecialchars('quiz_id='.$_SESSION[action][quiz_id].'&uid=0&score_id='.$_SESSION[quiz][score_id].'&offsite=1', ENT_QUOTES); ?>'; } echo"<iframe src=\"http://www.commander.com/app/score.php?$param\" width=\"480\" height=\"925\" scrolling=\"no\" frameborder=\"0\" marginheight=\"0\" marginwidth=\"0\"></iframe>"; echo"<?= htmlspecialchars($show_commander, ENT_QUOTES); ?>"; <?= htmlspecialchars("?>", ENT_QUOTES); ?> Quote Link to comment https://forums.phpfreaks.com/topic/119064-outputing-php-tags-in-a-textarea/#findComment-613113 Share on other sites More sharing options...
DarkWater Posted August 11, 2008 Share Posted August 11, 2008 Whoa, what's going on with that? First of all, don't use short tags. >_< Secondly, you cannot execute PHP code inside a function call...You need to separate it out. if ($something == true) { $foo = $something; } else { $foo = 'bar'; } echo htmlspecialchars($foo); Quote Link to comment https://forums.phpfreaks.com/topic/119064-outputing-php-tags-in-a-textarea/#findComment-613155 Share on other sites More sharing options...
cesarcesar Posted August 11, 2008 Author Share Posted August 11, 2008 Whoa, what's going on with that? Its dirty.. but it works. First of all, don't use short tags. >_< short tags is on by default on most servers these days. Secondly, you cannot execute PHP code inside a function call...You need to separate it out. Read my post again and you will see what im doing. You miss read my post. My use of PHP in code is necessary in this instance. Otherwise, thank you for your time in reply. Quote Link to comment https://forums.phpfreaks.com/topic/119064-outputing-php-tags-in-a-textarea/#findComment-613330 Share on other sites More sharing options...
Andy-H Posted August 11, 2008 Share Posted August 11, 2008 use stripslashes(htmlentities($data, ENT_QUOTES)); It needs a little more formatting but I never got that far... Quote Link to comment https://forums.phpfreaks.com/topic/119064-outputing-php-tags-in-a-textarea/#findComment-613332 Share on other sites More sharing options...
cesarcesar Posted August 11, 2008 Author Share Posted August 11, 2008 use stripslashes(htmlentities($data, ENT_QUOTES)); This is an option i have recently seen and will be trying in my cleanup session. thanks/ Quote Link to comment https://forums.phpfreaks.com/topic/119064-outputing-php-tags-in-a-textarea/#findComment-613333 Share on other sites More sharing options...
Wuhtzu Posted August 11, 2008 Share Posted August 11, 2008 Maybe take a minute to think about putting it outside a text area and use php's build-in "source displaying and highlighting"-function http://dk.php.net/manual/pl/function.highlight-string.php http://dk.php.net/manual/pl/function.highlight-file.php I personally prefer it the way this forum handles it... Put it in a <div> (maybe with scrolling, maybe without) and give the div another background color. This will also allow you to use syntax highlighting which I think is great Quote Link to comment https://forums.phpfreaks.com/topic/119064-outputing-php-tags-in-a-textarea/#findComment-613334 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.