FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


PHP Code to HTML





phpjsfan
Hello People,

Is there a utility available (a free one if possible) that formats php/javascript code as cut-and-paste HTML? I just want the indenting and fonts should be correct, though some syntax highlighting would be great.

thanks in advance
AOP Web Development
you can try phpedit, dreamweaver, notepad++,php designer... or any.. just try to google Very Happy
MrBlueSky
Shameless plug: http://www.frihost.com/users/MrBlueSky/blog/vp-82436.html Wink

Another option is the PHP library geshi. It supports creating HTML from source code for all common languages. I created this online tool once for converting source to HTML or BBcode using geshi: http://www.mrbluesky.frih.net/syntax/syntax.php
phpjsfan
AOP Web Development wrote:
you can try phpedit, dreamweaver, notepad++,php designer... or any.. just try to google Very Happy


I don't know if I phrased my question wrongly...
what I want is a utility that takes php / js code and formats it as html for display, so that I can put it in a web page where it will show up as indented and highlighted php/js code.

I use notepad++ for php/js coding regularly, but I don't know if it has the facility to do this...
If it has this feature, where is it hidden? can anyone help me out?
SlowWalkere
Ahh... that makes more sense.

There's a couple of ways you can partially achieve the effect you're looking for.

To simply get the HTML tags to be shown and not get rendered, you can surround the whole code example in <xmp> and </xmp> tags.

Another interesting solution I saw was to convert all of the < and > characters to &gt and &lt. Tedious work... but some clever guy wrote a simple app (sHTMLc) to convert the html code for you.

Either of those methods should work to allow the HTML to be displayed on the screen instead of rendered by the browser.

For the tabbing/spacing problem, use the <pre> tag. It maintains most spacing in the document, so your tabs and extra white space will be shown. This is great for showing code/scripts. For the HTML, you'll have to use one of the methods above and then wrap the output in a <pre> tag.

As for syntax highlighting, I don't know of an easy method to do that. I suppose you could use <span> tags and a stylesheet over each piece of code you wanted highlighted in a color. Doing that by hand would be very tedious for more than a few lines of code.

It would be a pretty simple app to build, if you've already got a system to detect what needs to be highlighted. Perhaps someone already made one? Methinks this would be a good candidate for a plug in for Notepad++ or some other open source coding program.

Edit: That's a nifty program, MrBlueSky. Is there a way to use it within another php file (i.e. to display a short bit of code) rather than to have it render the entire file highlighted?

Good luck,
- Walkere
MrBlueSky
SlowWalkere wrote:


Edit: That's a nifty program, MrBlueSky. Is there a way to use it within another php file (i.e. to display a short bit of code) rather than to have it render the entire file highlighted?



You can use the geshi library. Then you can syntax highlight pieces of code very easily:

Code:

include_once('geshi.php');
$geshi = new GeSHi($source, $language);
echo $geshi->parse_code();


Where $source is the source code to format.
Agent ME
A really easy way to show php code online with automatic syntax highlighting - put the file online with the extension .phps . By default that extension is parsed by the server's php into an html file that has the php source code highlighted.
phpjsfan
MrBlueSky wrote:

You can use the geshi library. Then you can syntax highlight pieces of code very easily:

Code:

include_once('geshi.php');
$geshi = new GeSHi($source, $language);
echo $geshi->parse_code();


Where $source is the source code to format.


This seems to be the answer. I also stumbled on the fact that Pear has a text-highlighter package which supports multiple languages. The demo I saw even had line numbers.
manav
i had used geshi before and it works good...
mahirharoon
to convert html to php
just copy the code and put the echo thingy in all lines
i do not think it works
for ph editor
use dev-php
http://devphp.sourceforge.net/
even php.net uses it
Related topics
Show PHP Code
Difference between PHP and HTML docs
PHP CODE INCLUSION
How to change extension php to html but the php script still
mySQL Query/PHP code - get the highest value...
my PHP code benchmark script that got some problems
PHP code snippit?
Folder structure and file names - index or name, php or html
CSS for making images go through a php code.
Gradient Fill Cell
What is a good or bad php code?
I want PHP Code to ......
PHP inside HTML tags?
editing webpages (.php or .html) without database/cms?
Highlight PHP-code in a HTML-document
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.