Category Archives: PHP

chr

Syntax: string chr ( int $ascii ) Description: Returns a one-character string containing the character specified by ascii. Example 1 <?php $str=”hai”.chr(32).”how”.chr(32).”are”.chr(32).”you”; echo $str; ?> OUTPUT hai how are you Example 2 <?php echo sprintf(“1*1=%c”, 49); echo ‘<br/>’; echo sprintf(“1*2=%c”, 50); ?> OUTPUT 1*1=1 1*2=2  

current, next, prev, end

Syntax: mixed prev ( array &$array ) Description: Checks if a value exists in an array <?php $transport = array(‘foot’, ‘bike’, ‘car’, ‘plane’); $mode = current($transport); // $mode = ‘foot’; $mode = next($transport); // $mode = ‘bike’; $mode = next($transport); // $mode = ‘car’; $mode = prev($transport); // $mode = ‘bike’; $mode = end($transport); // […]

Download File Using Php

I added the code to download the file using php. When we apply this concept, dont need to give the file dirctory to user. <?php function downloadfile($filepath){ if(file_exists($filepath)){ // Change it based on file extension or type $type=”application/zip”; header(“Pragma: public”); header(“Content-Type: $type”); header(“Cache-Control: public”); header(“Content-Description: File Transfer”); header(“Content-Disposition: attachment;filename=\””.basename($filepath)); header(‘Content-Length: ‘.filesize($filepath)); header(“Content-Transfer-Encoding: binary”); header(“Expires: 0”); […]

PHP First Program

Syntax PHP echo Syntax See the below table to get the opening and closing tags of php Opening Tag Closing Tag <?php ?> <? ?> <script language=’php’> </script> PHP echo The echo statement insert text into a web page. It is the common statement in php. We can echo a statement using following types Single Quotes Double […]

How to Enable .htaccess in WAMP Server

To Enable .htaccess in WAMP Server use the following steps STEP  1:  click on Wampserver and select apache->httpd.conf  STEP  2: Find and replace the following text Find      #LoadModule rewrite_module modules/mod_rewrite.so Replace   LoadModule rewrite_module modules/mod_rewrite.so  STEP  3: Restart Wamp Server  Now .htaccess will work successfully

in_array

Syntax: bool in_array ( mixed $needle , array $haystack [, bool $strict = FALSE ] ) Description: Checks if a value exists in an array <?php $os = array(“Mac”, “NT”, “Irix”, “Linux”,1); if (in_array(“Irix”, $os)) { echo “Got Irix<br/>”; } if (in_array(“mac”, $os)) { echo “Got mac<br/>”; }else echo ‘false<br/>’; if (in_array(“1”, $os,false)) { echo […]

Password Generator In PHP

Password Generator In PHP. We can generate dynamic password with numeric, alphanumer etc using php. I created dynamic_password function. It will generate and return the dynamic password. You should have to send password type, length like sha1, md5 for password type and numeric value for password length. <?php function dynamic_password($type=”,$length=10){   // Dynamic password function […]

PHP Array Functions

Function Example OR Syntax array_change_key_case array_chunk array_combine array_count_values array_diff array_diff_key array_diff_assoc array_diff_uassoc array_diff_ukey array_fill array_filter array_flip array_intersect array_intersect_assoc array_intersect_key array_intersect_uassoc array_keys array_key_exists array_map array_merge array_multisort array_pop array_push array_rand array_replace array_reverse array_search array_shift array_slice array_splice array_sum array_unique array_unshift array_values current, next, prev, end end sort in_array