PHP Serialize Defination 

 

The serialize function convert any PHP variable value into a string. Basically  serialize is most often used for storage of complex variables for future use. The string can be convert into the original value using unserialize.

 

 

   Serialized string syntax 

 

Example :

 

$myarray = array('name' => 'Arifhossen', 'address' => 'dhaka-bangladesh');
$serialize_string = serialize($myarray);


 
Variable Type Syntax Example - PHP Example - Result
Integer i:<value> serialize(2); i:2;
Decimal / Float d:<value> serialize(2.1); d:2.100000000000000088817841970012523233890533447265625;
String s:<string length>:<value> serialize('one'); s:3:"one";
Array a:<array length>:{<value><value>...} serialize(array('first' => 'one', 'second' => 2)); a:2:{s:5:"first";s:3:"one";s:6:"second";i:2;}
Object O:<type string length>:<property count>:{<property value><property value>...} serialize(new stdClass()); O:8:"stdClass":0:{}

 

 


Tags : php,  

 

<?php

 

   $sentense = 'I love programming. Basically php programming.';
    $search_keyword = 'love php programming';

 

   //call hightlight keyword class

 


    $word_highlight_obj = new word_search_and_highlight($sentense , $search_keyword);


    echo $word_highlight_obj->result;

 

 

?>

 

 <?php


    class word_search_and_highlight
    {
        public $result;
 
        function __construct($text, $words)
        {
            $split_words = explode( " " , $words );
            foreach ($split_words as $word)
            {
                $color = self::generate_colors();
                $text = preg_replace("|($word)|Ui" ,
                           "<span style=\"background:".$color.";\"><b>$1</b></span>" , $text );
            }
            $this->result = $text;
        }
 
        private function rgbhex($red, $green, $blue)
        {
            return sprintf('#%02X%02X%02X', $red, $green, $blue);
        }
 
        private function generate_colors()
        {
            $red = rand( rand(60,100) , rand(200,252) );
            $green = rand( rand(60,100) , rand(200,252) );
            $blue = rand( rand(60,100) , rand(200,252) );
 
            $color = self::rgbhex( $red , $green , $blue );
            return $color;
        }
    }

 

 

?>

 

 

 




 

  XML File Download by php , Cakephp :Source Code

 <?php

 

        $FileName = 'yourfile.xml';   

 

        $Path = WWW_ROOT.'files'.DS.'ctscan'.DS;    

     
        header('Content-Type: text/xml');


        header("Content-Length: " . filesize($Path.$FileName));


        header("Content-Disposition: attachment; filename=$FileName");      

     
        readfile($Path.$FileName); 

 

?>


Tags : cakephp,  xml,  php,