Showing posts with label php. Show all posts
Showing posts with label php. Show all posts

Tuesday, 20 February 2018

php FFMpeg extract images from videos

php FFMpeg extract images from videos in every 10 or nth seconds

Question: From where download the PHP FFMpeg library?
Install the php FFMpeg with composer.
composer require php-ffmpeg/php-ffmpeg



Question: Check php FFMpeg installed properly or not?
require 'vendor/autoload.php';
$ffmpeg = FFMpeg\FFMpeg::create();
print_r($ffmpeg);

If it will print the object means FFMpeg is proper configure.


Question: How to extract image from video?
require_once 'ffmpeglib/vendor/autoload.php'; 
$folderPath='convert/';

#Create the required Object
$ffmpeg = FFMpeg\FFMpeg::create();
$video = $ffmpeg->open($folderPath.'video.mp4');

#extra the image at 10 seconds
$video
    ->frame(FFMpeg\Coordinate\TimeCode::fromSeconds(10))
    ->save('frame_10.jpg');


#extra the image at 20 seconds
$video
    ->frame(FFMpeg\Coordinate\TimeCode::fromSeconds(20))
    ->save('frame_20.jpg');


#extra the image at 30 seconds
$video
    ->frame(FFMpeg\Coordinate\TimeCode::fromSeconds(30))
    ->save('frame_30.jpg');



Question: How to extract image in every 10 seconds from video?
    require_once 'ffmpeglib/vendor/autoload.php'; 
    $folderPath='convert/';

    ##Create the required Object
    $ffmpeg = FFMpeg\FFMpeg::create();
    $video = $ffmpeg->open($folderPath.'video.mp4');

    for($i=10; $i<=300; $i+=10){
        $video
            ->frame(FFMpeg\Coordinate\TimeCode::fromSeconds($i))
            ->save($folderPath.'frame_'.$i.'.jpg');            

    }



Question: How to set the binary file path in ffpeg?
$ffmpeg = FFMpeg\FFMpeg::create(array(
    'ffmpeg.binaries'  => '/opt/local/ffmpeg/bin/ffmpeg',
    'ffprobe.binaries' => '/opt/local/ffmpeg/bin/ffprobe',
    'timeout'          => 3600, // The timeout for the underlying process
    'ffmpeg.threads'   => 12,   // The number of threads that FFMpeg should use
));



Question: How to get the codec_name information of video?
$ffprobe    = \FFMpeg\FFProbe::create();
$codeAc=$ffprobe->streams($uploadingFileName[0])
        ->videos()
        ->first()
        ->get('codec_name');



Question: How to get the duration of video?
$ffprobe    = \FFMpeg\FFProbe::create();
$codeAc=$ffprobe->streams($uploadingFileName[0])->get('duration');        



Question: How to combine multiple video?
$staticFilePath='/videopath';
$video = $ffmpeg->open( $staticFilePath.'0.mp4');
        $video
        ->concat(array($staticFilePath.'0.mp4',$staticFilePath.'1.mp4',$staticFilePath.'2.mp4',$staticFilePath.'3.mp4'))    
        ->saveFromSameCodecs($staticFilePath.'final.mp4', TRUE);
//final.mp4 will be combined file



Question: How to combine multiple video from h265 to h264?
$staticFilePath='/videopath';
$video = $ffmpeg->open( $staticFilePath.'0.mp4');
$video
        ->concat($array($staticFilePath.'0.mp4',$staticFilePath.'1.mp4',$staticFilePath.'2.mp4',$staticFilePath.'3.mp4'))
        ->saveFromDifferentCodecs(new FFMpeg\Format\Video\X264,$staticFilePath.'final_264.mp4', true);  




Tuesday, 6 February 2018

php is not recognized as an internal or external command wamp

Question: How to "Fix php is not recognized as an internal or external command wamp"?

Step 1
Click on Start Button => Right Click on Computer => Click on Properties

Window 7 go to the properties


Step 2
An Popup will appear => Click on "Advance System Setting" (Left Panel)


Step 3
Click on "Environment Variable"

Window 7 go to the System properties


Step 3
A popup will appear, Select PATH and click on "EDIT"
Window 7 Edit Environment Varaible



Step 4 Add you php.exe path at the end of input box like below:
;D:\wamp\bin\php\php5.5.12\

Window 7 Set php.exe path in environment variable


Friday, 6 October 2017

How to install ffmpeg in wamp server in Windows7

How to install ffmpeg in wamp server in Windows

Question: What are Simple steps to install ffmpeg in wamp server in Windows?
  1. Download FFmpeg for Windows
    https://ffmpeg.zeranoe.com/builds/
  2. Extract the downloaded Zip file.
  3. Copy bin/ffmpeg.exe, bin/ffplay.exe and bin/ffprobe.exe from downloaded and paste in C:\Windows\System32
  4. Create a folder with name ffmpegtest in path d:/wamp/www (Drive can be different as per wamp installation)
  5. Login to Command prompt and go to d:/wamp/www/ffmpegtest using cd command
  6. Execute following command (To download composer)
    php -r "readfile('https://getcomposer.org/installer');" | php
    

    It will download the composer.phar
  7. Execute following command to download PHP-FFMPEG library.
    php composer.phar require php-ffmpeg/php-ffmpeg
    
  8. Test the FFMPEG with php
    include "vendor/autoload.php";
    $ffmpeg = FFMpeg\FFMpeg::create();
    print_r($ffmpeg);
    
    When it print the object, means FFMPEG setup successfully.

Question: How to convert .wav to .mp3?
include "vendor/autoload.php";
$ffmpeg = FFMpeg\FFMpeg::create();
$video = $ffmpeg->open( 'audiofile.wav' );
$audio_format = new FFMpeg\Format\Audio\Mp3();
// Extract the audio into a new file as mp3 and save in folder
$video->save($audio_format, 'audiofile.mp3');



Question: How to transcode a wav to flac?
include "vendor/autoload.php";
$ffmpeg = FFMpeg\FFMpeg::create();
$video = $ffmpeg->open( 'audiofile.wav' );
$audio_format = new FFMpeg\Format\Audio\Mp3();
$video->save($audio_format, 'audiofile.mp3');


Tuesday, 3 October 2017

How to create built in web server in PHP?

How to create built in web server in PHP

Question: In which PHP Version Built-in web server come?
PHP 5.4


Question: Can we run php without apache?
Yes, We can run the php independent.


Question: Can we test our application with Built-in web server feature?
Yes, We can.


Question: Can we test our application with Built-in web server feature?
Yes, We can use this feature to test our module.


Question: Can we go LIVE with Built-in web server ?
Not, Its recommended We should not go LIVE with this Built-In Web Server.


Question: How to check If built-in Web server is available in your PHP Build?
Way 1
print the phpinfo() in php. and Search for Built-in HTTP server , If found means It is available.

Way 2
in php command line, execute following command

php -h

Search -S (Run with built-in Web server), If found means It is available.


Question: How to run PHP Script with built-in Web Server?
Go to file Location and execute following command from command line.
php -S 0.0.0.0:8080 myfile.php



Question: What is use of -S?
It is used to specify the Ip Address with port with which bind.


Question: What is use of -t?

It is used to specify the target folder.


Question: How to detect the request by built-in Web Server?
if(php_sapi_name()=='cli-server'){
    echo "this is request by built-in Web Server";
}



Question: Give full working example of built-in Web Server?
  1. Create a file hello.php
  2. Login to command line
  3. Go to that particular folder in command line
  4. Execute following command.
    php -S 0.0.0.0:8080 hello.php
    



Tuesday, 19 September 2017

Standard PHP Library (SPL) with Basic details

Standard PHP Library (SPL) with Basic details

Question: What is full form of SPL?
Standard PHP Library.


Question: What is SPL?
It is collection of interfaces and Classes.


Question: Do we need to download library for SPL?
No, We need not to download external library.


Question: What does provide SPL?
SPL provides following Iterators, Interface and Functions.
  1. Set of standard Data Structure.
  2. a Iterators to traverse over objects
  3. Set of Interfaces
  4. Set of standard Exceptions
  5. SPL Functions
  6. SPL File Handling



Question: What classes are available in SPL data structure?
Doubly Linked Lists: It is a list of nodes linked in both directions to each other. Iterator operations, access to both end node, addition or removal of nodes.
http://php.net/manual/en/class.spldoublylinkedlist.php

Heaps: Heaps are tree-like structures that follow the General heap, each node is greater than or equal to its children.
http://php.net/manual/en/class.splheap.php

Arrays: Arrays are structures that store the data in a continuous way, accessible via indexes.
http://php.net/manual/en/class.splfixedarray.php

Map: A map is a datastructure holding key-value pairs. PHP arrays can be seen as maps from integers/strings to values.
http://php.net/manual/en/class.splobjectstorage.php



Question: What Iterators classes are available in SPL?
  1. AppendIterator
  2. ArrayIterator
  3. CachingIterator
  4. CallbackFilterIterator
  5. DirectoryIterator
  6. EmptyIterator
  7. FilesystemIterator
  8. FilterIterator
  9. GlobIterator
  10. InfiniteIterator
  11. IteratorIterator
  12. LimitIterator
  13. MultipleIterator
  14. NoRewindIterator
  15. ParentIterator
  16. RecursiveArrayIterator
  17. RecursiveCachingIterator
  18. RecursiveCallbackFilterIterator
  19. RecursiveDirectoryIterator
  20. RecursiveFilterIterator
  21. RecursiveIteratorIterator
  22. RecursiveRegexIterator
  23. RecursiveTreeIterator
  24. RegexIterator



Question: What Interfaces are available in SPL?
  1. Countable
  2. OuterIterator
  3. RecursiveIterator
  4. SeekableIterator
  5. SplObserver
  6. SplSubject



Question: What Exception classes are available in SPL?
  1. BadFunctionCallException
  2. BadMethodCallException
  3. DomainException
  4. InvalidArgumentException
  5. LengthException
  6. LogicException
  7. OutOfBoundsException
  8. OutOfRangeException
  9. OverflowException
  10. RangeException
  11. RuntimeException
  12. UnderflowException
  13. UnexpectedValueException



Question: What are the advantage of iterators?
  1. Laziness: the data is only fetched when you actually need it.
  2. Reduced memory usage: SPL iterators encapsulate the list and expose visibility to one element at a time making them far more efficient.



Question: Give an example of Iterating Arrayst?
  
$arr = array("One", "Two", "three", "Four", "Five", "Six");
$iter = new ArrayIterator($arr);
foreach ($iter as $key => $value) {
    echo $key . ":  " . $value ;
}

Output
  
0: One
1: Two
2: three
3: Four
4: Five
5: Six



Question: Give an example of Iterating Directory Listings?
  
$dir = new DirectoryIterator("/");
foreach ($dir as $item) {
    echo $item . "
";
}

Output
  
$RECYCLE.BIN
Backup
banner
blog backup
data
data.log.txt
desktop files
doremon
mm
mongodb



Question: Give an example of Iterating Directory Recursively?
  
$iter = new RecursiveDirectoryIterator("/");
foreach (new RecursiveIteratorIterator($iter) as $item) {
    echo $item . "
";
}



Wednesday, 28 December 2016

How to install redis on wamp server?

How to install redis on wamp server?

Question: What is redis?
it is an open source advanced key-value database storage system like NoSQL.


Question: Why It is used?
Redis is used for caching to speed up web application.


Question: How redis helpful in Optimization?
Redis operations can be executed on the server side and reduce the client's workload.


Question: What type of data can be stored in redis server?
Redis store complex data structures like strings, hashes, lists, sets, sorted sets, bitmaps and hyperlogs as its key values.


Question: Why redis is fast?
Redis is inherently fast as it stores data in memory.


Question: How to install redis in wampserver?
  1. Download the redis
       A) Download Redis setup For 32 Bit System and Install
       B) Download Redis Setup for 64 Bit system and follow below steps.    
    1. Extract the zip file
    2. Place the unzip file in c:\redis
    3. Run redis-server.exe from c:\redis
    4. then Run redis-cli.exe from c:\redis
  2. Check out your php version and know whether thread safety is enabled or not(by using phpinfo()).
  3. Now we need to download the php_redis.dll. Download the php_redis.dll from PECL.
    Download as per PHP Version and thread based.
  4. Extract the zip file.
  5. Copy the php_redis.dll and paste to following folder in Wamp Server.
    wamp\bin\php\php5.x.xx\ext\
  6. Add the following line in your php.ini
    extension=php_redis.dll
  7. Re-start the wamp Server.
  8. Do phpinfo() and search redis. It will start displaying which means its Redis is installed
  9. Learn and Work with redis.



Question: How to check redis is installed Or Not?
try {
    $redis = new Redis();
    $redis->connect('localhost', 6379);
    $redis->set('name', 'Redis is Installed');
    echo $glueStatus = $redis->get('name');
    
} catch (Exception $ex) {
    echo $ex->getMessage();
}



Wednesday, 14 December 2016

How to add number of days to a date?

How to add number of days to a date?

Question: How to add number of days to a current date?
echo date('Y-m-d', strtotime("+10 days"));

It would add 10 days to the current date.


Question: How to subtract number of days to a current date?
echo date('Y-m-d', strtotime("-10 days"));

It would subtract 10 days to the current date.


Question: How to add number of days to a on given date?
$date = new DateTime('2016-12-14');
echo date('Y-m-d', ($date->getTimestamp()+ (3600*24*10) )); //3600 = 1 hour

It would add 10 days to the current date.


Question: How to subtract number of days to a given date?
$date = new DateTime('2016-12-14');
echo date('Y-m-d', ($date->getTimestamp()- (3600*24*10) )); //3600 = 1 hour

It would subtract 10 days to the current date.


Friday, 23 September 2016

New PHP 7 Feature List

New PHP 7 Feature List

Question: Why we should use PHP 7 as compare to PHP5?
  1. Improved performance. Its twice as fast as PHP 5.
  2. Lower Memory Consumption.
  3. Scalar type declarations.
  4. Return and Scalar Type Declarations.
  5. Consistent 64-bit support
  6. Many fatal errors converted to Exceptions
  7. Secure random number generator.
  8. Various old and unsupported SAPIs and extensions are removed from the latest version
  9. null coalescing operator removed
  10. Anonymous Classes Added.
  11. Zero cost asserts
  12. PHP 7 uses new Zend Engine 3.0



Question: What is PHPNG?
PHPNG branch has been merged into master and has been used as the base for PHP 7.0.
PHPNG target is improve the performance and memory usage efficiency of PHP.


Question: What is a PHP parser?
PHP parser is a software which understand your coding and convert to computer language So that it can be executed & gives a output in HTML.


Question: What is a Scalar type declarations?
Allowing/prohibited datatype declaration in functions know for Scalar type declarations.
There are two options in Scalar type declarations
1) Coercive Mode (default)
2) Strict Mode
function sum(int ...$ints) {
      return array_sum($ints);
   }
   print(sum(2, '20', 4.2)); //26.2



Question: How to use return type declarations?
 function returnIntValue(int $value): int {
      return $value;
   }
   print(returnIntValue(5));



Question: What is spaceship operator?
It is Operator which is used to compare two expressions.
It return -1, 0 or 1.
print( 1 <=> 1); //0
print( 1 <=> 2); //-1
print( 2 <=> 1); //1




Question: Can define accept an array?
Yes, It can. For Example:
define('CLIENTS', [
    'client 1',
    'client 2',
    'client 3'
]);



Question: What is use of Closure::call() in PHP7?
It is used to temporarily bind an object scope to a closure and invoke it.
For Example:
 class A {
      private $x = 1;
   }
   $value = function() {
      return $this->x;
   };
   print($value->call(new A));



Question: How to import import Classes using single use statement?
Before PHP 7
use com\mytestclass\ClassA;
use com\mytestclass\ClassB;
use com\mytestclass\ClassC as C;

In PHP 7
 use com\mytestclass\{ClassA, ClassB, ClassC as C};



Question: What are Deprecated features in PHP7?
Following are deprecated feature in PHP7.
  1. Old Style Constructure.
     class A {
          function A() {
             print('Deprecated');
          }
       }
    
  2. Static calls to non-static methods.
    class A {
          function b() {
             print('Deprecated');
          }
       }
       A::b();
    
    
  3. password_hash() salt



Question: What extension are removed ?
  1. ereg
  2. mssql
  3. mysql
  4. sybase_ct



Question: From where I can download PHP7?
http://php.net/downloads.php


Question: How to setup PHP7 with WampServer?
http://www.wampserver.com/en/


Friday, 19 February 2016

How to detect Mobile Device in PHP? - Simplest way

How to detect Mobile Device in PHP - Simplest way

Question: What does this script do?
It simply detect the request and tells request comes from mobile browser (Mobile devices) OR Web Devices (Desktop, Laptop, Ipad).


Question: What are Server Requirements for this script?
PHP Must be installed.


Question: Why we do need this script?
Sometime we need to give the different response on the behalf of devices.
For Example:
We give 20 records for web browser.
We give 10 records for Mobile browser.


Question: Where we do need this script? Give Example?
We need this script where we change the response on the behalf of devices browser.
For Example:
  1. Different number of record in web and in mobile.
  2. In Responsive website, we hide the extra information which is not displayed in mobile devices. In this case we should also not fetch these details from the server.
  3. Display the different sizes of images on the behalf of device.
  4. If website is not compatiable to mobile devices, Give a good message to users.



Question: How to detect the mobile devices?
$useragent=$_SERVER['HTTP_USER_AGENT'];
$isMobile=0;
if(preg_match('/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i',$useragent)||preg_match('/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i',substr($useragent,0,4))){
    $isMobile=1;
}

if($isMobile){
    /** Script For Mobile **/

    /** Script For Mobile **/
}else{
    /** Script For Web**/

    /** Script For Web**/
}



Saturday, 30 January 2016

What is Zend Engine in PHP

Zend Engine is used internally by PHP as a complier and runtime engine. PHP Scripts are loaded into memory and compiled into Zend opcodes. These opcodes are executed and the HTML generated is sent to the client.

What is Zend Engine



The Zend Engine is an open source scripting engine, commonly known for the important role it plays in the web automation language PHP. It was originally developed by Andi Gutmans and Zeev Suraski while they were students at the Technion - Israel Institute of Technology.

Monday, 22 June 2015

How to Upgrade PHP 5.3 to PHP 5.4 in WAMP Server in window 7


Adding addons  PHP 5.4 in WAMP Server is quite easy, just you need to follow the following (Works for me).

Please take the backup of code and database before Start.

Please make the backup of php.ini files. When we add addons in wamp server then, we can access the new PHP (php5.4) and old php (php5.x). Both are easily accessible.

Just to need to change the PHP Version like Below:

How to Upgrade PHP 5.3 to PHP 5.4 in WAMP Server in window 7

Let Suppose following:
1) Addin 5.4.42
2) Wamp Server drive is E:


Follow the following steps to upgrade your PHP version.

  1. Download PHP5.4 From http://windows.php.net/download/#php-5.4 (Download Thread Safe)
  2. Go to PHP Folder Location (i.e E:\wamp\bin\php)
  3. Create a new folder with name php5.4.42.
  4. Extract the download files and save in E:\wamp\bin\php\php5.4.42.
  5. Copy the following files from your old PHP directory to your new PHP directory ().
        php.ini
        phpForApache.ini
        wampserver.conf
    
  6. Open new copied php.ini file.
  7. Update the extension_dir path in file.
  8. Open new phpForApache.ini file.
  9. Update the extension_dir path in file.
  10. Reboot your system.
  11. Start wamp Server
  12. Go to wampserver =>PHP=>Version=>PHP 5.4.42
  13. Now running PHP5.4.42
    Note: you might need to Re-enable the PHP extension like CURL, Openssl etc

Monday, 25 May 2015

How can I upload file asynchronously in php?

How can I upload file asynchronously in php?

Following are simple 4 Steps to upload file asynchronously  in PHP.

Step #1
Add jQuery javascript file in your page - Need for Ajax call.


<script src="//code.jquery.com/jquery-1.11.3.min.js"></script>


Step #2
Add Following Html, where you want to show the button to upload the file.






Step #3:
Add following javascript code which is responsible for uploading the file.
URL: /folder/upload-file.php
Description: Here you need to write the send the request to server.
$( document ).ready(function() {
    $(':button').click(function(){
        var formData = new FormData($('form')[0]);
        $.ajax({
            url: '/folder/upload-file.php', //Location of upload file 
            type: 'POST',
            xhr: function() {  // Custom XMLHttpRequest
                var myXhr = $.ajaxSettings.xhr();
                return myXhr;
            },

            beforeSend: function(data){},
            success: function(data){},
            error: function(data){},        
            data: formData,        
            cache: false,
            contentType: false,
            processData: false
        });
    });
});


Step #4
Add Following code in "/folder/upload-file.php" which will upload the file in Server.
$targetFile="/path/to/upload/file";//Location of srver
if (move_uploaded_file($_FILES["file"]["tmp_name"], $targetFile)) {
        echo "success";
    } else {
        echo "failure";
    }





Wednesday, 25 February 2015

How to store array in Cookie and retrieve array from cookie

How to store array in Cookie and retrieve array from cookie

How to store array in Cookie
We need to json_encode the array then save the data with setcookie function.
$arrayData=array(
    'web technology experts',
    'web technology experts Notes',
    'web technology experts Notes  php technology'    
);
setcookie('cookieData', json_encode($arrayData));


How to Retrieve array in Cookie
As we have encoded the array above, So we need to json_decode the array before use.
$arrayData = json_decode($_COOKIE['cookieData']);


How to set time in cookies
$arrayData=array(
    'web technology experts',
    'web technology experts Notes',
    'web technology experts Notes  php technology'    
);
setcookie('cookieData', json_encode($arrayData), time()+3600);// set time for 1 hour [1 hour=3600 seconds]


 


Tuesday, 16 December 2014

get_class_vars PHP Function

array get_class_vars ( string $class_name )
Get the default properties of the class
Get the default properties of the given class.

<?phpclass myclass {

    var 
$var1// this has no default value...
    
var $var2 "xyz";
    var 
$var3 100;
    private 
$var4// PHP 5

    // constructor
    
function myclass() {
        
// change some properties
        
$this->var1 "foo";
        
$this->var2 "bar";
        return 
true;
    }

}
$my_class = new myclass();$class_vars get_class_vars(get_class($my_class));

foreach (
$class_vars as $name => $value) {
    echo 
"$name : $value\n";
}
?>


OOP PHP #16 : fungsi get_class_vars() dan get_class_method

Tuesday, 19 August 2014

ob_get_level -Return the nesting level of the output buffering mechanism

int ob_get_level ( void )
Return the nesting level of the output buffering mechanism
Returns the nesting level of the output buffering mechanism.

For users confused about getting "1" as a return value from ob_get_level at the beginning of a script: this likely means the PHP ini directive "output_buffering" is not set to off / 0. PHP automatically starts output buffering for all your scripts if this directive is not off (which acts as if you called ob_start on the first line of your script).



If your scripts may end up on any server and you don't want end-users to have to configure their INI, you can use the following at the start of your script to stop output buffering if it's already started:

<?phpif (ob_get_level()) ob_end_clean();?>

Alternatively, you can use the opposite if you always want to have an output buffer at the start of your script:

<?phpif (!ob_get_level()) ob_start();?>