Nick.LaPrell.org

PHP Utility Functions

utility_functions.php contains various PHP functions I wrote. Most functions are based on string and array manipulation and are detailed below:

writeFile(string $name, string $contents) -- Quickly stores $contents in a file named $name. If the file exists, it is overwritten.

trim_chars_from_end(string $string, int $n) -- Trims $n characters off the end of $string and returns the result.

trim_chars_from_front(string $string, int $n) -- Trims $n characters off the beginning of $string and returns the result.

ftp_file_exists(resource $conn_id, string $file) -- Uses FTP commands to see if $file exists using $conn_id as the FTP resource.

arrayDeleteByValue(array $array, mixed $value [, string $x]) -- Deletes the first, last, or every occurrence (set in $x -- default is every occurrence) of $value found in $array and returns the resulting array.

arrayInsertAfterKey(array $array, mixed $insert_value, mixed $index) -- Inserts $insert_value after $index in $array. The array can be iterative or associative. The resulting array is returned.

arrayInsertBeforeKey(array $array, mixed $insert_value, mixed $index) -- Inserts $insert_value before $index in $array. The array can be iterative or associative. The resulting array is returned.

arrayInsertAfterValue(array $array, mixed $insert_value, mixed $after_value [, string $method]) -- Inserts $insert_value after the first, last, or every occurrence (set in $method -- default is first) of $after_value.

arrayInsertBeforeValue(array $array, mixed $insert_value, mixed $before_value [, string $method]) -- Inserts $insert_value before the first, last, or every occurrence (set in $method -- default is first) of $before_value.

Download

Version Release Date Release Notes Download
1.0 December 6, 2007

More to come. I threw this together just to get it out. If you find any bugs or have any suggestions for improvements, please feel free to contact me at Nick@LaPrell.org.