Thursday, December 23, 2010

Converting double pricision to binary

echo decbin(round('put double precision no here'));

Monday, October 11, 2010

php-soap configuration

INSTALLATION OF nusoap ON UBUNTU

1.To enable SOAP support, configure PHP with --enable-soap .

2.sudo aptitude install php-soap

3.The behaviour of these functions is affected by settings in php.ini.

SOAP Configure Options Name Default Changeable Changelog
soap.wsdl_cache_enabled 1 PHP_INI_ALL
soap.wsdl_cache_dir /tmp PHP_INI_ALL
soap.wsdl_cache_ttl 86400 PHP_INI_ALL
soap.wsdl_cache 1 PHP_INI_ALL
soap.wsdl_cache_limit 5 PHP_INI_ALL

Saturday, September 25, 2010

No of occurrences of substring in a string.

function strposOffset($search, $string, $offset)
{
    /*** explode the string ***/
    $arr = explode($search, $string);
    /*** check the search is not out of bounds ***/
    switch( $offset )
    {
        case $offset == 0:
        return false;
        break;
  
        case $offset > max(array_keys($arr)):
        return false;
        break;

        default:
        return strlen(implode($search, array_slice($arr, 0, $offset)));

    }
}


$offset = 2;

/*** the string to search for ***/
$search = 'is';

/*** the string to search ***/
$string = 'this is a best way to get no of occurrences of a substring in a string ';

echo $p= strposOffset($search, $string, $offset);
if($p=='')
echo 'not found'
?>

Tuesday, August 3, 2010

__set() & __get() Magic Methods

In the below example class Foo uses set and get methods while class Bar uses the magic methods. To summarise set and get, basically if you are trying to access a property of an object (and it has a get method) the name of the property you are requesting is passed into the get method and it can handle it how it wants. set works the same but it is only called when you attempt to assign a value to a member variable. The only difference being set takes two paramemters, the variable its setting and the value. 




class Foo{

    private $name;
    private $age;

    public function setName($name){
        $this->name = $name;
    }

    public function getName(){
        return $this->name;
    }

    public function setAge($age){
        $this->age = $age;
    }

    public function getAge(){
        return $this->age;
    }

}

$foo = new Foo();
$foo->setName("Dougal");
$foo->setAge(10);

echo $foo->getName(). " is " . $foo->getAge(). " years old\n";

class Bar{

    private $name;
    private $age;

    public function __set($var, $val){
        $this->$var = $val;
    }

    public function __get($var){
        return $this->$var;
    }

}
$bar = new Bar();
$bar->name = "Dougal";
$bar->age = 10;

echo $bar->name . " is " . $bar->age. " years old";
?>

Ajax Cache-Problem with Internet Explorer.

Include those lines into php file.

header('Pragma: no-cache');
header('Cache-Control: no-cache');
header('Expires: 0');

Word Wrap in php

$text "A very long woooooooooooord.";$newtext wordwrap($text8"\n"true);

echo 
"$newtext\n";?>

PHP Scripting in Command line

1. How can I execute a PHP script using command line?
Ans : “php filename” or “php -f filename” will run a php file in command line.

ZEND BLOG

http://shiflett.org/blog/2005/apr/zend-certification-self-test

ZEND TEST BOOK

http://www.boysj.com/the-zend-php-certification-practice-test-book

PHP CLASSES AND IF/ELSE BLOCK

//*********************************working
$flag='3';

if($flag=='3')
{
class cc {
function __construct() {
echo 'cc!';

}
}

}

$type = 'cc';
$obj = new $type;
//****************************************not working

$type = 'cc';
$obj = new $type;
$flag='3';

if($flag=='3')
{
class cc {
function __construct() {
echo 'cc!';

}
}

}


?>

what is interface in php? how it is use?


An Interface is like a template similar to abstract class
with a difference where it uses only abstract methods.

In simple words, an interface is like a class using
interface keyword and contains only function
declarations(function with no body).

An Interface should be implemented in the class and all the
methods or functions should be overwridden in this class.

for eg: 

interface InterfaceName{
  function fun1();
  function fun2(a,b);    
}

class ClassName implements InterfaceName{
  fuction fun1(){
    function implementation.......
  }
  fuction fun2(a,b){
    function implementation.......
  }
}

Tuesday, April 6, 2010

PHP Redirect

  1. 
       header( 'Location: http://www.yoursite.com/new_page.html' ) ;
    
    ?>
    Change the code on the redirect page to be simply this. You need to replace the URL above with the URL you wish to direct to.
  2. Be sure that you do not have any text sent to the browser before this, or it will not work. Your safest bet is to simply remove all content from the page but the redirect code.
    
    
    
       //this will NOT work, the browser received the HTML tag before the script
    
    
       header( 'Location: http://www.yoursite.com/new_page.html' ) ;
    
    ?>

No - Cache

set_time_limit(180000);
    header("Expires: Thu, 31 Dec 2020 20:00:00 GMT");
    header('Pragma: no-cache');
    header('Cache-Control: no-cache');
    header('Expires: 0');

Monday, March 29, 2010

Functions in IMAP, POP3 AND LDAP?

imap_body — Read the message body.

imap_check — Check current mailbox.

imap_delete — Mark a message for deletion from current mailbox.

imap_mail — Send an email message.