Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/119064-outputing-php-tags-in-a-textarea/
Share on other sites

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); ?>

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);

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.

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.