Outputing PHP tags in a Textarea

Discussion in 'PHP' started by cesarcesar, Aug 10, 2008.

  1. #1
    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);
    Code (markup):
    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>'; ?>
    Code (markup):
    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>"; ?>
    Code (markup):
    Where am i going wrong? Thanks for the help.
     
    cesarcesar, Aug 10, 2008 IP
  2. cesarcesar

    cesarcesar Peon

    Messages:
    188
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    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); ?>
    Code (markup):
     
    cesarcesar, Aug 10, 2008 IP
  3. rohan_shenoy

    rohan_shenoy Active Member

    Messages:
    441
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    60
    #3
    Or escape the tag characters with a backslash if its causing problems. Ideally it should not because when its inside quotations, it is treated a a string.
     
    rohan_shenoy, Aug 10, 2008 IP