views:

30

answers:

2

I have started making a syntax highlighter in php (only a quick one) and so far I have got a code box generator (aka it creates a table with styles that looks good and can display source code and html code). At the moment when writing code with it I do this:

$code = "def example_ruby_code(does_it_work)
" .     "(insert tab here) @does_it_work = false
" .     "end"
codebox($code, "title_here.rb")

My trouble is that I know that I can't have tabs in html so I used the following:

preg_replace("/\t/", "&nbsp&nbsp&nbsp&nbsp ", $code)

(this went in the codebox function) But it doesn't seem to work, the output just shows no indentation whatsoever. Any ideas? Thanks in advance, ell.

+3  A: 

You are missing semi-colon after &nbsp:

preg_replace("/\t/", "    ", $code);

Note: You may find highlight_string function useful.

Sarfraz
A: 

Thanks for the semi-colon thing but I'v realised I'v been a complete moron, instead of setting the new value I just called preg_replace! Silly me! Thanks anyway, it still wouldn't of worked without the semi colons. Thanks :)

Ell