PHP String Builder
Jan 26th
PHP String Builder using array()
<?php
class TStringBuilder {
/**
* Number of items added to Collection
* @var int
*/
private $count = null;
/**
* String Array
* @var array
*/
private $str = null;
/**
* Initializes a new instance
*/
public function __construct() {
$this->count = 0;
$this->str = array();
}
/**
* Adds new string
* @param string $str
*/
public function add($str) {
++$this->count;
$this->str[] = $str;
return $this;
}
/**
* Clears the string
*/
public function clear() {
$this->count = 0;
$this->str = array();
}
/**
* Gets internal array
*/
public function get() {
return $this->str;
}
/**
* Dumps string
* @param string $seperator
* @return string
*/
public function dump($seperator = "") {
$retVal = "";
foreach ($this->str as $k) {
$retVal .= $k . $seperator;
}
return substr($retVal, 0, strlen($retVal) - strlen($seperator));
}
/**
* Dumps string continiously
*/
public function dumpc() {
foreach ($this->str as $k) {
echo $k;
}
}
/**
* Get number of enteries added
* @return int
*/
public function count() {
return $this->count;
}
/**
* Get string length
* @return int
*/
public function length() {
$retVal = 0;
foreach ($this->str as $k) {
$retVal += strlen($k);
}
return retVal;
}
}
PHP array_keys_exist function
Jan 26th
PHP array_keys_exist function
sample:
/* test */
$result = array_keys_exist (array('key1', 'key2'), $_GET);
/**
* result
* will be true if key1 and key2 are exist in $_GET
*/
Code:
/**
* Validates the given key(s) if exist in array
* @author Fatih Piristine <v-fpiris@teknober.com>
* @param array $needle
* @param array $haystack
* @return boolean
*/
function tws_array_keys_exist(array $needles, array $haystack) {
foreach ($needles as $needle) {
if (!isset($haystack[$needle])) {
return false;
}
}
return true;
}
note: you can replace isset with array_key_exists function if you need to check the keys those have null values.
PHP working with JSON and stdClass
Jan 26th
<?
class TJSONBuilder extends Countable {
/**
* JSON collection object
* @var unknown_type
*/
private $json = null;
/**
* Number of items added to json collection
* @var unknown_type
*/
private $count = 0;
/**
* Initializes a new instance of the TJSONBuilder class
*/
public function __construct() {
$this->json = new stdClass();
}
/**
* Insert new node
* @param string $json_string
* @param boolean $assoc
* @param integer $deep
*/
public function add($json_string, $assoc = false, $deep = 5) {
$id = null;
$decode = json_decode($json_string, $assoc, $deep);
foreach ($decode as $k => $v) {
$id = $k;
break;
}
if (isset($id)) {
$this->json->{$id} = $decode->{$id};
++$this->count;
}
}
/**
* Clear nodes
*/
public function clear() {
$this->json = new stdClass();
$this->count = 0;
}
/**
* Get json class
* @return Ambiguous
*/
public function get() {
return $this->json;
}
/**
* Dump as json string
* @param constant $json_options
* @return string
*/
public function toString($json_options = JSON_FORCE_OBJECT) {
return json_encode($this->json, $json_options);
}
/**
* Get number of nodes
* @return int
*/
public function count() {
return $this->count;
}
}
Install BugZilla on Apache with mod_perl
Jan 26th
here are the steps followed during the installation, the instructions on web gave me a lot of headache. Download necessary files before you start!
Note: after upgrading Perl modules works with Bugzilla 4.0.1 too.
Extract BugZilla to C:\BugZilla (more…)
PHP DOMDocument appendHTML
Jan 26th
Appending returned document fragment is enough for this operation.
public function appendHTML($rawHtml)
{
$tmp = $this->createDocumentFragment();
$tmp->appendXML($rawHtml);
return $tmp;
}
This function might throw invalid operation exception or parsing issues if your html string has no valid syntax
PHP GenericCollection using ArrayObject
Jan 26th
PHP GenericCollection using ArrayObject. Original Code can be found here:
just made little modification on it for own needs
HTTP Status Codes
Jan 26th
HTTP Status Codes ———————————————————————————— 200 : request completed (OK) 201 : object created, reason = new URI 202 : async completion (TBS) 203 : partial completion 204 : no info to return 205 : request completed, but clear form (more…)


LinkedIn
Twitter
Skype