Jump to content

[SOLVED] highlight_string within textarea?


newbtophp

Recommended Posts

<?php

$string = "<?php echo 'see it aint highlighted, the html tags from the highlight_string function interfer ';";

echo '<textarea style="width:100%; height:300px;">';

highlight_string($string);

echo '</textarea>';

?>

 

Is their any other way of making it function and look like a textarea? (with the same style) any alternative perhaps?  :-\

Link to comment
Share on other sites

I don't believe so. a textarea is basically a tiny version of a text editor (a very simple text editor) and so you can only edit the text as plain text. not to mention that highlight_string() returns your string with style tags around it

 

for example the following

<html>
<body>
<?php
highlight_string("Hello world! <?php phpinfo(); ?>");
?>
</body>
</html>

 

would return

<html>
<body>
<code>
<span style="color: #000000">Hello world! 
<span style="color: #0000BB"><?php phpinfo</span>
<span style="color: #007700">(); </span>
<span style="color: #0000BB">?></span>
</span>
</code>
</body>
</html>

Link to comment
Share on other sites

If you just want to be able to scroll you can set overflow:auto; and some sort of (max-)width/height.

 

I tried that and is as good as. Just a few issues though.

 

Im trying to disable the horizontal scroll (without hiding), so it just scroll vertically like a textarea.

 

I tried:

 

overflow-x: hidden;

overflow-y: scroll;

 

But that hides the horizontal scroll and the lines are overlapping into the hidden area. Is their anyway i can manipulate it so it dont scroll horizontal, it proceeds to next line in the frame. (like textarea)

 

Thanks

Link to comment
Share on other sites

You would have to look into word wrapping. But it would mess up the layout of the code. Example:

 

//$php contains PHP code
$high = highlight_string($php, true);
//convert non-breaking spaces to regular spaces
$high = str_replace(' ', ' ', $high);
echo '<div style="overflow: auto; width: 300px; height: 100px;">' . $high . '</div>';

Link to comment
Share on other sites

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.