Dont Panic!

Some utilities

PreviousPage NextPage

Updated: 19 Feb 16


Contact Me


Free Script and utilities

Table API generator

Data Unload


PHP Utils

Old SQL guide

Old PL/SQL guide

A Jersey Linux User Group?

PHP utilities (used in dbff)

Utilities that was written for dbff, but can be used independently. These are:

jdate - date-functions

	Date class functions:
	str2ts 		- Convert a string to a timestamp that can be used with eg "date()"
			- More strict than strtotime and could be replaced by php 5 functions
	format 		- Format a timestamp to a date with the dateformat set in the class.
	dateDiff 	- Calculate date difference in days.
	addDays 	- Add a number of days to a date.
	subtractDays 	- Subtract a number of days from a date.
	week 		- Retorn ISO week for a date.
	weekStartDate 	- Get the start date of a week
	chkDtTimeArr 	- Check if an array with date or datetime elements are a valid date/time
	dtStr2dtArr 	- Convert a date-string to a "date-array"
	getElements 	- Pars a date string according to format, and returns all date elements found.
	All functions sets error message in errmsg string if they fail.

jff - file-functions

	Class contains basic functions for reading and writing to files,
	readLine, writeLine, open, close, lock, unlock, writeArray, readFiletoArr.
	If an error occur functions return NULL or FALSE.
	readLine also sets errorCode to:
		-100 if "end of file" is gotten, or to
		-101 if called to read a file that does not exists
	All functions sets error message in errmsg string if they fail.

jutl - general utilities

	Class Functions: 
	hasIntValue 	- checks if string only contains interger characters,
	hasVarValue 	- checks if value is not null or empty,
	nvl 		- returns given value if testvalue is null
	quoteStr 	- Enclose a string with double quotes, if array, number or boolean
			  they are left intact, A boolean is converted into string TRUE or FALSE
	unQuoteStr 	- Removes quotes from a string
	cnv2uc 		- Converts a string to upper case, and if an array all elements are converted.
	str2logical 	- Returns TRUE/FALSE/NULL from a string with these words or trimmed string if either.
	getWord 	- Fetches next word from a string and returns word + rest in an array 
	getuTime 	- Fetch utime for timing purposes
	prArr 		- Print an array or arrays in arrays.

jtags - Csv and json tag utilities

	Class Functions: 
	TagStr	 	- Tags a string with tags
	arr2TagStr 	- Converts an array to a tagged string
	setTagInfo 	- Sets tag values
	mkTaggedLine	- Tags a line to tagged string
	getTaggedString - Get values from a tagged string
	getJsonObj 	- Makes a json string to an array
	getCSVObj 	- Makes a csv string to an array

dbff (data-base flat-file)

The dbff php script is a flat-file record, data utility. I wrote it first because I wanted to have an all php based web site, but with some "database" functionality, without having to use a database just to read or write a couple of hundreds of records here and there. Only tested on linux with php 4.x & 5.x. Strict conversion to php5 has not yet been done.

These functions may replace a more advanced database, if the requirement is moderate, and performance and concurrency is not an issue. It is not in any way as advanced as a more sophisticated database system, but many times these functions are enough to provide file access in a database manner and it could replace a database system that otherwise would be overkill for a simple function or small application. It is NOT a relational database even if it uses functions names borrowed from SQL and mimics some relational database functionality. I used it for a number of years and it supports both read, write, sort, keys, selection and more.

Records are either tagged and have a field delimiter/csv style, non quoted or use a couple of json formats.
Sample mixed csv and tagged record format: <R>Hong Kong;HK;HKG</R> (type 1) or
<R I=1123537376>1;5;1123537376;0;23:42 whatever data;></R> (type 2),

or Jason format style: { U=1674798486: [623, "Homage", 33, 234453, "abc", "20060701","Y"] } (type 3)
or { pkfld: 1, ukfld: 1, nfld: 0.33333333333333, dtfld: 20080408125222 } (type 4)

Sample Record definition:
$rec_def = array (
   'id'	     => array ('size'=>10, 'type'=>'INT',  'pk'=>sequence),
   'name'    => array ('size'=>20, 'chkNN'=>true),
   'phone'   => array ('size'=>25, 'chkNN'=>true,  'chkMinLen'=>6),
   'email'   => array ('size'=>30, 'type'=>'Email, 'lower'=>true),
   'units'   => array ('size'=>2,  'type'=>'INT',  'chkList'=> array(1,3,5)),
   'created' => array ('size'=>12) 'type'=>'date', 'default'=>'now');

Test functions for datatypes and some other check functions ( as shown above ) like: 
	chkInt, Field value must be an Integer,
	chkNum, Field value must be a Number,
	chkEmail, Field must look like an email, format check only,
	chkDateTime, Field must be a date-time, 
	chkDate, Field must be a date. As DateTime but without the time part.

The zip file contains code with dbff.php (main file), utilities needed, a doc-file and rc4crypt.php to use if you like to have your data encrypted and a directory with test-scripts, that also may serve as examples. The code is commented to make it possible to change parameters and some behaviour of the code.

Code is released under the terms of the GNU General Public License as published by the Free Software Foundation.

Nice things


And OpenSource Sw


I use fedora linux

try it or try

Ubuntu or PcLinuxOs

Share information and knowledge!


I'm based in Jersey, Available for assignments in all of Europe, On-Site or Remote. Call or mail me!


Jersey Opera House