ncyoung.com

You are here: Top->Programming->Web->PHP



php documentation generator

Just found PHPXref, a documentation generator for php applications. It shows include hierarchies and lets you follow functions from the file they're used in to the file they're defined in. It generates a set of HTML files to represent the application

It's good software in that although it's not the most comprehensive docs generating package ever, the ratio of what it demands in order work to what it delivers in functionality is very good. You can run it against any PHP application and get the cross referencing features. With a tiny bit of work formatting the comments on each function a certain way, it will pick up those as well.

It's written in perl, which I think is a perfect statement on the state of PHP.

bBlog has the docs generated by PHPXref online here.

auto convert < br > tags in php

If you show text with line breaks (returns) in an HTML page, the line breaks will be ignored and the text will show up as a big blob.

If you are using PHP to show the text, you can replace all the line breaks with HTML break tags, which will make it show up closer to what you probably intended. If your test is in a variable called $string, you can create breaks tags with the following line of php code:

$string = preg_replace("/\n/","\n<BR>n",$string);

php out buffers to better use php templating in functions

I figured out a cool trick for PHP. I've always noticed that the templating engines fall down when you begin to write subroutines. In other words, if you want to return string output from a function rather than immediately printing that as the function runs, you must use string concatenation rather than PHP's templates.



For example:


$string = tester();
print "this will print second<br>";
print $string; //will do nothing

function tester(){
?>
this will print first.
<?php
}

But you can use PHP's nifty output buffering to save up all the template output within the subroutine like so:



$string = tester();
print "this will now be first<br>";
print $string;

function tester(){
ob_start();
?>
this will be second.
<?php
$ret = ob_get_contents();
ob_end_clean();
return $ret;
}

Nifty, huh?