PHPiSean Posted November 19, 2011 Share Posted November 19, 2011 Basically, I'm trying to take a string from the db and do two things. [*]Prevent html from being processed as html (htmlspecialchars() i think) [*]Recognize PHP code and highlight it. This is a reply system much like what I'm typing right now. For example 2, I want to be able to do this <?php echo "hello"; ?> I've researched a little and found a function called highlight_php(). The problem I run into now is that I only want to highlight php when it is needed. I am stuck as to where to go next. My thoughts would be 2 regex functions, however I don't know which one to call first. Any suggestions? Everything is appreciated Link to comment https://forums.phpfreaks.com/topic/251412-highlighting-code-and-others/ Share on other sites More sharing options...
QuickOldCar Posted November 19, 2011 Share Posted November 19, 2011 http://php.net/manual/en/function.highlight-file.php and also http://www.php.net/manual/en/function.highlight-string.php Link to comment https://forums.phpfreaks.com/topic/251412-highlighting-code-and-others/#findComment-1289468 Share on other sites More sharing options...
ZulfadlyAshBurn Posted November 19, 2011 Share Posted November 19, 2011 use this <?php $tohighlight = "<?php echo 'hello'; ?>"; highlight_string($tohighlight); ?> EDIT: i just reedited the code. this should do the trick. Link to comment https://forums.phpfreaks.com/topic/251412-highlighting-code-and-others/#findComment-1289487 Share on other sites More sharing options...
trq Posted November 19, 2011 Share Posted November 19, 2011 You will be much better off using a third party library such as Geshi. Link to comment https://forums.phpfreaks.com/topic/251412-highlighting-code-and-others/#findComment-1289500 Share on other sites More sharing options...
ZulfadlyAshBurn Posted November 19, 2011 Share Posted November 19, 2011 i would have to agree with thorpe even me myself uses geshi for my websites. Link to comment https://forums.phpfreaks.com/topic/251412-highlighting-code-and-others/#findComment-1289504 Share on other sites More sharing options...
PHPiSean Posted November 19, 2011 Author Share Posted November 19, 2011 Thanks for the replies. I see what you mean, however there won't always be code in the user's reply. I only want to highlight the code when there is code. Link to comment https://forums.phpfreaks.com/topic/251412-highlighting-code-and-others/#findComment-1289563 Share on other sites More sharing options...
trq Posted November 19, 2011 Share Posted November 19, 2011 So, you need to implement some form of bbocde similar to this boards tags. If you google "php bbcode" you should find plenty of examples of how to do so. Link to comment https://forums.phpfreaks.com/topic/251412-highlighting-code-and-others/#findComment-1289594 Share on other sites More sharing options...
PHPiSean Posted November 19, 2011 Author Share Posted November 19, 2011 So, you need to implement some form of bbocde similar to this boards tags. If you google "php bbcode" you should find plenty of examples of how to do so. Right, Thanks. This is what I was looking for. Link to comment https://forums.phpfreaks.com/topic/251412-highlighting-code-and-others/#findComment-1289596 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.