# PHP Code highlighting

**URL:** <https://forum.kirupa.com/t/php-code-highlighting/58318>\
**Category:** programming\
**Created:** [July 21, 2004, 3:37pm UTC](https://forum.kirupa.com/t/php-code-highlighting/58318 "2004-07-21T15:37:28Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![jw06](https://avatars.discourse-cdn.com/v4/letter/j/838e76/32.png) [@jw06](https://forum.kirupa.com/u/jw06)\
**Post date:** [July 21, 2004, 3:37pm UTC](https://forum.kirupa.com/t/php-code-highlighting/58318/1 "2004-07-21T15:37:28Z")

</div>

Hello, I am trying to make a add a tutorial on the fly system to my website… and I was wondering how do I make something like this?

```php

print "Test";
echo 'test';

```

I am just wondering how to highlight the blocks of PHP code ect…

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 21, 2004, 3:38pm UTC](https://forum.kirupa.com/t/php-code-highlighting/58318/2 "2004-07-21T15:38:58Z")

</div>

What you’re referring to is a plugin in vBulletin. I think there are other scripts that will do it for you though for non forum use. Try a google search.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 21, 2004, 3:41pm UTC](https://forum.kirupa.com/t/php-code-highlighting/58318/3 "2004-07-21T15:41:40Z")

</div>

Alright… any idea on what it may be called? just try PHP highlighting?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 21, 2004, 3:46pm UTC](https://forum.kirupa.com/t/php-code-highlighting/58318/4 "2004-07-21T15:46:39Z")

</div>

> [@jw06](#):
>
> Alright… any idea on what it may be called? just try PHP highlighting?

There’s a package called ‘code2html’, which can convert any code (PHP, C, C++, Java) to HTML - you have to run it once-per-file, so you can’t just do it on the fly…

The other option, and the one I tend to use most often, is to actually create a unique PHP file, and then symlink it to a .phps file, and then configure the webserver to do the highlighting for me… It’s built into PHP - files with the correct mime type will be highlighted automatically. The problem, then, is displaying that on your page.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 21, 2004, 3:49pm UTC](https://forum.kirupa.com/t/php-code-highlighting/58318/5 "2004-07-21T15:49:25Z")

</div>

o… alright…

well im going to go search around and see what I can find.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 21, 2004, 4:45pm UTC](https://forum.kirupa.com/t/php-code-highlighting/58318/6 "2004-07-21T16:45:41Z")

</div>

> [@jw06](#):
>
> o… alright…
> 
> well im going to go search around and see what I can find.

There is a function in PHP to do what you’re needing:  
[http://us3.php.net/highlight\_string](http://us3.php.net/highlight_string)

Also, read the comments on that page, they are quite useful 🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 22, 2004, 3:13pm UTC](https://forum.kirupa.com/t/php-code-highlighting/58318/7 "2004-07-22T15:13:13Z")

</div>

😃 😃 😃 Thanks!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 22, 2004, 3:21pm UTC](https://forum.kirupa.com/t/php-code-highlighting/58318/8 "2004-07-22T15:21:56Z")

</div>

cool little function!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 23, 2004, 4:25am UTC](https://forum.kirupa.com/t/php-code-highlighting/58318/9 "2004-07-23T04:25:08Z")

</div>

```php

show_source(basename($_SERVER['PHP_SELF']));

```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 23, 2004, 4:26am UTC](https://forum.kirupa.com/t/php-code-highlighting/58318/10 "2004-07-23T04:26:24Z")

</div>

but as mentioned before, using highlight\_string is better because it highlights it rather than just showing the code 😛

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 23, 2004, 5:12am UTC](https://forum.kirupa.com/t/php-code-highlighting/58318/11 "2004-07-23T05:12:11Z")

</div>

it hightlights it aswell :), differants is that highlight\_string only hightlights the string you want it to hightlight…

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 23, 2004, 5:16am UTC](https://forum.kirupa.com/t/php-code-highlighting/58318/12 "2004-07-23T05:16:09Z")

</div>

oh my bad :(, guess I should check before making dumb posts like that :P, but then what’s the difference between that and highlight\_file?

edit: nevermind, they’re duplicates 😉

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 23, 2004, 5:18am UTC](https://forum.kirupa.com/t/php-code-highlighting/58318/13 "2004-07-23T05:18:37Z")

</div>

Nothing dumb about it… can’t know it all 🙂

hightlight\_file ( didnt even know that one lol )

```
   The **highlight_file()** function prints out a syntax highlighted version of the code contained in filename using the colors defined in the built-in syntax highlighter for PHP.     

   If the second parameter return is set to **TRUE** then **highlight_file()** will return the highlighted code as a string instead of printing it out. If the second parameter is not set to **TRUE** then **highlight_file()** will return **TRUE** on success, **FALSE** on failure.     

```

[size=1]ssssssssssssstt [/size]still learning 🙂 [Highlight\_file for those who want to know](http://www.php.net/highlight_file/)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 23, 2004, 5:24am UTC](https://forum.kirupa.com/t/php-code-highlighting/58318/14 "2004-07-23T05:24:16Z")

</div>

yep, just was looking at it, and a while back I forgot about the second parameter, man was that one long night until I figured that out 😛
