Teknober Blog

Blog

Follow me on TwitterRSS Feeds

  • Home
  • About
  • Updates

PHP String Builder

Jan 26th

Posted by editor in Development

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;
    }
}
builder, php, php countable, php string builder, string, string builder

PHP array_keys_exist function

Jan 26th

Posted by editor in Development

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.

array, array_keys, array_keys_exist, array_key_exists, php

PHP working with JSON and stdClass

Jan 26th

Posted by editor in Development

<?
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;
    }
}
json, php, php json objects, php json stdclass, stdClass

Install BugZilla on Apache with mod_perl

Jan 26th

Posted by editor in Administration

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…)

apache, bugzilla, bugzilla perl windows, mod_perl

PHP DOMDocument appendHTML

Jan 26th

Posted by editor in Development

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

appendhtml, dom, php

PHP GenericCollection using ArrayObject

Jan 26th

Posted by editor in Development

PHP GenericCollection using ArrayObject. Original Code can be found here:

just made little modification on it for own needs

http://php.net/manual/en/class.arrayobject.php

(more…)

array, class, collection, generic, object, php

HTTP Status Codes

Jan 26th

Posted by editor in ASP.Net

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…)

apache, code, header, http, iis, status
«12345
    • Recent comments
    • Popular posts
    • Archives
    • Tags
    • Categories
    • Administration (16)
      • Database Servers (3)
        • Cassandar NoSQL (1)
        • MariaDB Server (2)
        • Micsoft SQL Server (1)
        • MySQL Server (3)
      • DNS Servers (1)
        • Bind (1)
        • Microsoft DNS (1)
      • GIT (1)
      • OpenSSL (1)
      • SVN (2)
      • VMWare (1)
      • Web Servers (10)
        • Apache HTTPd (9)
        • Internet Information Services (4)
      • Windows Servers (3)
    • Development (39)
      • ASP.Net (5)
      • C (3)
      • CSharp (1)
      • CSS (2)
      • HTML (6)
      • JavaScript (7)
        • JSON (1)
      • PHP (27)
        • PDO (8)
      • SQL (7)
      • VBScript (2)
    apache array array_keys backup builder class clear collection configuration cookies dns dom element enabled error eventlogs file generic get header html http iis ip javascript json log mysql object pdo pdo statement php php html validation PHP PDO port select size skip startup statement stdClass string take vbscript windows
    • February 2012 (1)
    • January 2012 (2)
    • December 2011 (1)
    • September 2011 (4)
    • June 2011 (4)
    • May 2011 (3)
    • April 2011 (5)
    • March 2011 (6)
    • February 2011 (1)
    • January 2011 (20)
    • PHP PDO Statement Object with CSV and JSON (0)
    • PHP PDO Using reserved words as column names (0)
    • PHP Validate HTML ID using regular expression (0)
    • PHP Validating HTML Class using regular expression (0)
    • PHP TNullClass using IteratorAggregate (0)
    • PHP PDO using Transactions with TModel::GenerateStatement functions (0)
    • JavaScript Object Push method (0)
    • Windows EventLogs Backup (0)
    • Windows EventLogs Clear (0)
    • VMWare on Debian 6 with Linux-Kernel-2.6.32-5 (0)
  • Partners

    • AcemCity Turizm Taşımacılık Organizasyon
    • Acemoglu Tur – Personel Tasimaciligi ve Servis Hizmetleri
    • Piristine KFT
    • Teknober Web Services
Copyright © Teknober
LinkedIn LinkedIn Twitter Twitter Skype Skype
grab this