PHP Archives

Force redirection from http to https in php

The following script will redirect the url from http to https:

//Or you can use like following:

PHP zip_entry_compressionmethod() Function

The zip_entry_compressionmethod() function returns the compression method of a zip archive entry.

syntax — >zip_entry_compressionmethod(zip_entry)

zip_entry –> Required. Specifies the zip entry resource to read (a zip entry opened with zip_read() )

 

Ex:-

<?php

$zip = zip_open(“test.zip”);

if ($zip)

{

while ($zip_entry = zip_read($zip))

{

echo “<p>”;

echo “Name: ” . zip_entry_name($zip_entry) . “<br />”;

echo “Compression Method: ”

. zip_entry_compressionmethod($zip_entry);

echo “</p>”;

}

zip_close($zip);

}

?>

 

output:

Name: ziptest.txt

Compression Method: deflated

Name: htmlziptest.html

Compression Method: deflated

Unzoom a picture in php

There are several options:

imagecopyresampled() using GD
Imagick::resizeImage() using ImageMagick

Regex to return only the file extension.

//Returns Only the File extension.

function get_file_extenstion($filename) {

if( !preg_match(‘/\./’, $filename) ) return ”;

return preg_replace(‘/^.*\./’, ”, $filename);

}

//Convert MM/DD/YYYY to YYYY-MM-DD. This format is useful if you want to insert into a MySQL date field.

Incoming search terms:

  • date format conversion in magento from dd/mm/yyyy to yyyy-mm-dd

//Returns File Name stripping off the characters after hyphen in a file name.

function file_hyphen_strip($filename){

return preg_replace(‘/\-[^-]*$/’, ”, $filename);

}

Incoming search terms:

  • titanium regular expression hypens

The following code snippet will show you how to apply custom function recursively to every member of an array:

That’s it

The following code will check whether a key exists in an array or not:

That’s it!

Creating First PHP Cookie

When you create a cookie, using the function setcookie, you must specify three arguments. These  arguments are setcookie(name, value, expiration):

1.  name: The name of your cookie. You will use this name to later retrieve your cookie, so don’t forget it!

2.  value: The value that is stored in your cookie. Common values are username(string) and last visit(date).

3.  expiration: The date when the cookie will expire and be deleted. If you do not set this expiration date, then it will be treated as a session cookie and be removed when the browser is restarted.

In this example we will be creating a cookie that stores the user’s last visit to measure how often people return to visit our webpage. We want to ignore people that take longer than two months to return to the site, so we will set the cookie’s expiration date to two months in the future!

 

 

Page 4 of 9« First...23456...Last »