require "./mklib.php"; ?> require "./mk_datetime.php"; ?>
The latest version of the mklib.php library and this example page is at
mklib.php home: http://blazonry.com/scripting/mklib
File Functions |
getFileExtension()
Parses the passed filename and returns just the extension, defined by everything after the last period.
Example
$f1 = "sample.txt"; $f2 = "sample.filename.test.txt"; print "
\n"; print " \$f1: $f1 \n"; print " getFileExtension(\$f1): " . getFileExtension($f1) . " \n"; print " \$f2: $f2 \n"; ?> getFileExtension(\$f2): " . getFileExtension($f2) . "
getFilenameSansExt()
Parses the passed filename and returns just the filename portion without the extension.
Example
$f1 = "sample.txt"; $f2 = "sample.filename.test.txt"; print "
\n"; print " \$f1: $f1 \n"; print " getFilenameSansExt(\$f1): " . getFilenameSansExt($f1) . " \n"; print " \$f2: $f2 \n"; ?> getFilenameSansExt(\$f2): " . getFilenameSansExt($f2) . "
Text Functions |
procDisplayText()
Formats text to be displayed in a browser. It converts line breaks to <br> and converts http://(.*) to live HTML links.
Example
$str = "This is a URL: http://www.blazonry.com/"; print "
\n"; print " \$str: $str \n"; ?> procDisplayText(\$str): " . procDisplayText($str) . "
procDBText()
Prepares a string for inserting into a database. Depending on the different settings (0,1,2) it allows for different HTML tags to be inserted.
0 - Allows No HTML or PHP tags 1 - Allows for B,I, 2 -Example
$str = 'Here\'s some text with bold tags and print "PHP"; ?> tags'; print "
\n"; print " \$str: ".htmlentities($str)." \n"; print " procDBText(\$str,0) ".procDBText($str,0)." \n"; print " procDBText(\$str,1) ".procDBText($str,1)." \n"; ?> procDBText(\$str,2) ".procDBText($str,2)."
mk_substr()
Chops a string close to the given length, trying to make the cut at a space. It moves backwards cutting more than the specified length.
Example
$pos ="01234567890123456789012345678901234567890"; $str = "This is my string, there are many like it but this one is mine."; $cutstr = mksubstr($str,40); print "
\n"; print " Counter: $pos
\n"; print " Original: $str
\n"; ?> Cut String: $cutstr
format_bytes()
Formats passed bytes into a more human readable format, converting to "kb" and "mb" when appropiate, kinda like the -h option for df or ls.
Example
$b1 = "123456789"; $b2 = "25689"; $b3 = "1024"; print "
\n"; print " Bytes 1: $b1 \n"; print " Bytes 2: $b2 \n"; print " Bytes 2: $b3 \n"; print " Formatted B1: ".format_bytes($b1)." \n"; print " Formatted B2: ".format_bytes($b2)." \n"; ?> Formatted B3: ".format_bytes($b3)."
Date/Time Functions |
procDate()
Converts a passed date in varying mm-dd-yyyy formats into a sql compatible yyyy-mm-dd. If a two-digit year is passed to it is assumed to be 19xx if greater than 70, and 20xx if not. Used before inserting dates into database.
Example
$mydate1 = "3-26-99"; $mydate2 = "8-5-00"; $mydate3 = "10-15-01"; print "
\n"; print " \$mydate1: $mydate1 \n"; print " \$mydate2: $mydate2 \n"; print " \$mydate3: $mydate3 \n"; print " procDate(\$mydate1): ".procDate($mydate1)." \n"; print " procDate(\$mydate2): ".procDate($mydate2)." \n"; ?> procDate(\$mydate3): ".procDate($mydate3)."
revDate()
Reverses a SQL date from yyyy-mm-dd to mm-dd-yyyy, the common US date format. Used for displaying dates grabbed from database.
Example
$mydate = "2000-12-5"; print "
\n"; print " \$mydate: $mydate \n"; ?> procDate(\$mydate): ".revDate($mydate)."
blazonry.com
Last Updated: 2001-08-22