PHP HTML \t 和 Tab 问题
我已经开始在 php 中制作语法荧光笔(只是一个快速的),到目前为止我已经有了一个代码框生成器(又名它创建了一个样式看起来不错并且可以显示源代码和 html 代码的表格)。目前,当用它编写代码时,我这样做:
$code = "def example_ruby_code(does_it_work)
" . "(insert tab here) @does_it_work = false
" . "end"
codebox($code, "title_here.rb")
我的麻烦是我知道我不能在 html 中使用选项卡,所以我使用了以下内容:(
preg_replace("/\t/", "     ", $code)
这在 codebox 函数中) 但它似乎不起作用,输出只是显示没有任何缩进。有什么想法吗?预先感谢,嗯。
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/", "     ", $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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
注意: 您可能会发现
highlight_string
函数很有用。You are missing semi-colon after
:
Note: You may find
highlight_string
function useful.感谢分号的事情,但我意识到我是个十足的白痴,而不是设置新值,我只是调用 preg_replace!傻我啊!无论如何,谢谢,如果没有分号,它仍然无法工作。谢谢 :)
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 :)