Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2008
    Posts
    55

    Unanswered: Outputing PHP tags in a Textarea

    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
    Code:
    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

    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.
    Code:
    <? 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.

  2. #2
    Join Date
    Mar 2008
    Posts
    55
    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.
    Code:
    <?= 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); ?>
    Last edited by cesarcesar; 08-10-08 at 19:53.

  3. #3
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    I believe the correct way to do what you want is to replace all occurances of < & > with &lt; and &gt; respectively; finally wrapping the text in <pre> tags.

    Take note that <pre> tags were deprecated in XHTML and so won't be accepted when using a strict document type.
    George
    Home | Blog

  4. #4
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    Quote Originally Posted by georgev
    I believe the correct way to do what you want is to replace all occurances of < & > with &lt; and &gt; respectively; finally wrapping the text in <pre> tags.
    ..that should be handled by htmlspecialchars function. well except the <pre> tags
    I suspect the OP problem is that he probably shold have used htmlentities which will also encode other stuff such as the double quote
    I'd rather be riding on the Tiger 800 or the Norton

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •