Ghosts Syntax Highlighter

Started on the old forum in July 2012 · view the original in the archive · old links redirect here

7 replies · 591 views · started 14 years ago · 1 min read

3 participants
Ghost Senior · 366 posts #1

ok so i was building a syntax highlighter for my site/project that would mod the post/data before it hit the database so when a post was made only the correct parts of that post was highlighted within a codebox.

i came into an issue with the /** commented out text */ section of this as where it would comment the post out. but if a certain keyword from the php name array was in the commented out text it would then change to its respected color.

now ive had many suggestions to fixing this but all have failed when ive attempted it.

so im gonna let this out so anyone that wants to attempt to fix it or try and solve it can.

i should also add i have added a line of data inside the file for testing purposes to see the outcome and display the Demo of problem. i use the line of text for the testing/build of the script.

Demo of fill working AND problem http://the-immortals.uk.to/syntax-highlighter.php

File:

<?php include ('Ghost'); if ($Post == true) { echo ' ![](http://destrukt.dk/ico/phpdeveloper.jpg) alt='coding-talk.com!!' />'; echo 'Sharing Is Caring!'; } else { echo ' ![](http://img98.imageshack.us/img98/6476/av3ro4.jpg) alt='the username GHOST has been comprimised!' />'; echo 'OMG SOMEBODY HELP ME!!'; } ?>
arnage Lead · 811 posts #2

Test it with quotemeta(). 😉

<!DOCTYPE html PUBLIC "-//***WAPFORUM**.**RS***
Ghost Senior · 366 posts #3

arnage wrote: Test it with quotemeta(). ;)

oops accidently deleted the demo, (back up and running now)

and thank you, will look into the function.

edited sadly just like preg_quote this just added \ next to chars like $, it didnt however stop preg_replace or str_replace from find the word it was looking for. so it just ended up looking like.

$Variable bypassing the \ and still finding its mark.

also it didnt help much against none special symbols. for example: words from inside the arrays still get caught too.

/** some normal text then preg_replace **/ would appear.

<?php include ('Ghost'); if ($Post == true) { echo ' ![](http://destrukt.dk/ico/phpdeveloper.jpg) alt='coding-talk.com!!' />'; echo 'Sharing Is Caring!'; } else { echo ' ![](http://img98.imageshack.us/img98/6476/av3ro4.jpg) alt='the username GHOST has been comprimised!' />'; echo 'OMG SOMEBODY HELP ME!!'; } ?>
$XTREME$ Developer · 82 posts #4

ho , we can solve it ,wait

arnage Lead · 811 posts #5

Aha. Try to add something like this in snippet.

if (in_array($one, $two)) continue;

... to skip those predefined words.

<!DOCTYPE html PUBLIC "-//***WAPFORUM**.**RS***
Ghost Senior · 366 posts #6

arnage wrote: Aha. Try to add something like this in snippet.

if (in_array($one, $two)) continue;

... to skip those predefined words.

will look into it. thanks but this file now is starting to be a pain in my ass lol. thats why i put it up on forums 😉

<?php include ('Ghost'); if ($Post == true) { echo ' ![](http://destrukt.dk/ico/phpdeveloper.jpg) alt='coding-talk.com!!' />'; echo 'Sharing Is Caring!'; } else { echo ' ![](http://img98.imageshack.us/img98/6476/av3ro4.jpg) alt='the username GHOST has been comprimised!' />'; echo 'OMG SOMEBODY HELP ME!!'; } ?>
arnage Lead · 811 posts #7

Exactly why we should bounce ideas and try to make it right, you only to test those ideas only because you are most familiar with it, just if its not too much enoying to you. 🙂

<!DOCTYPE html PUBLIC "-//***WAPFORUM**.**RS***
Ghost Senior · 366 posts #8

arnage wrote: Exactly why we should bounce ideas and try to make it right, you only to test those ideas only because you are most familiar with it, just if its not too much enoying to you. :)

thats cool mate. although its not hard to see whats going on in the file.

top of file is all the arrays, and bottom half consists of 3 checks.

a 3 box check. a 2 box check a 1 box check.

and in each box check theres some preg_match_all, preg_replace, str_replace functions. thats basically it.

<?php include ('Ghost'); if ($Post == true) { echo ' ![](http://destrukt.dk/ico/phpdeveloper.jpg) alt='coding-talk.com!!' />'; echo 'Sharing Is Caring!'; } else { echo ' ![](http://img98.imageshack.us/img98/6476/av3ro4.jpg) alt='the username GHOST has been comprimised!' />'; echo 'OMG SOMEBODY HELP ME!!'; } ?>

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close