r/PHPhelp • • Apr 24 '25

Server Side Syntax Highlighting where the code blocks are part of a bigger string. How can I parse them out?

I am looking to do some server side syntax highlighting. However the content that needs to be highlighted, comes from a user created blog post. The users will have used a WYSIWYG style of input to craft the post, which when retrieved from the DB is a long string.

How can easily and reliably parse that resulting string variable for each <pre><code>...</code></pre> element? What do you guys recommend?

3 Upvotes

8 comments sorted by

View all comments

Show parent comment

1

u/johnnyfortune Apr 24 '25

Yes thanks! That project, along with Torchlight have me really wanting to try server side highlighting... I do have Prism.js working with Vite right now, and it looks and works pretty dang good, but its not as good with things like Antlers or Vue.js templates.