Jump to content

[SOLVED] highlight_string();


The Little Guy

Recommended Posts

in my database, I have a question, and sometimes the question has code with it.

 

it would look something like this in the database for example:

How would you replace a letter at a given position in a string?

 

<?php

    $a = 'fat';

?>

 

I would like to take that PHP, and place highlight_string(); around just the php portion, and not the question portion.

 

Anyone know the best way to do this?

Link to comment
https://forums.phpfreaks.com/topic/106496-solved-highlight_string/
Share on other sites

Add some style:

 

<style type="text/css">
  .question {
    font-weight: bold;
  }
  .question code {
    font-weight: normal;
  }
</style>
<p class="question"><?php print nl2br(preg_replace('/(\<\?php.+?\?>)/se','highlight_string(\'\\1\',1)',$text));?></p>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.