Wednesday, November 15, 2017

PHP Tutorial 2 - PHP Installation

What Do I Need To Start PHP?

To start using PHP, you can:
  • Find a web host with PHP and MySQL support
  • Install a web server on your own PC, and then install PHP and MySQL
A list with with best web servers you can find here.

Set Up PHP on Your Own PC

However, if your server does not support PHP, you must:
  • install a web server
  • install PHP
  • install a database, such as MySQL
The official PHP website (PHP.net) has installation instructions for PHP: http://php.net/manual/en/install.php

PHP Tutorial 1 - PHP Introduction

What You Should Already Know About PHP

Before you continue you should have a basic understanding of the following:
  • HTML
  • CSS
  • JavaScript

What is PHP?

  • PHP is an acronym for "PHP: Hypertext Preprocessor"
  • PHP is a widely-used, open source scripting language
  • PHP scripts are executed on the server
  • PHP is free to download and use

What is a PHP File?

  • PHP files can contain text, HTML, CSS, JavaScript, and PHP code
  • PHP code are executed on the server, and the result is returned to the browser (client) as plain HTML
  • PHP files have extension ".php"

What Can PHP Do?

  • PHP can generate dynamic page content
  • PHP can create, open, read, write, delete, and close files on the server
  • PHP can collect form data
  • PHP can send and receive cookies
  • PHP can add, delete, modify data in your database
  • PHP can be used to control user-access
  • PHP can encrypt data
With PHP you are not limited to output HTML. You can output images, PDF files, and even Flash movies. You can also output any text, such as XHTML and XML.

Why PHP?

  • PHP runs on various platforms (Windows, Linux, Unix, Mac OS X, etc.)
  • PHP is compatible with almost all servers used today (Apache, IIS, etc.)
  • PHP supports a wide range of databases
  • PHP is free. Download it from the official PHP resource: www.php.net
  • PHP is easy to learn and runs efficiently on the server side
PHP is the best :P

Tuesday, November 14, 2017

Create ZIP file with PHP


This is a script to create zip file containing different files. PHP has a ZipArchive class which can be used easily to create zip files. 
In this post we will learn how to create zip files in PHP. We will create zip files from different files.

// defined an array with names of files
$files = array('audio1.wav', 'audio2.wav', 'audio3.wav', , 'img1.png', 'img2.jpg');

// the name of zip archive
$zipname = 'file.zip';

//create ner class for zip
$zip = new ZipArchive;
//create new zip
$zip->open($zipname, ZipArchive::CREATE);

//make a loop for adding files into zip file
foreach ($files as $file) {
$zip->addFile($file);
}
//close zip
$zip->close();


This script is about creating zip file in PHP in the same location (folder). If we have different files we must defined the full location of files.
$files = array('./folder1/audio1.wav', './folder1/audio2.wav', './folder7/audio3.wav', 'img1.png', 'img2.jpg');

Monday, January 30, 2017

Free apache/mysql/php package for windows

1. WAMP Server


WAMPSERVER, a Windows web development environment.
WampServer is a Windows web development environment. It allows you to create web applications with Apache2, PHP and a MySQL database. Alongside, PhpMyAdmin allows you to manage easily your databases.

2. XAMPP Server


XAMPP is the most popular PHP development environment
XAMPP is a completely free, easy to install Apache distribution containing MariaDB, PHP, and Perl. The XAMPP open source package has been set up to be incredibly easy to install and to use.

3. EasyPHP


EasyPHP Devserver & Webserver
Develop with Devserver & Host with Webserver
PHP, Apache, MySQL, Nginx, PhpMyAdmin, Xdebug, PostgreSQL, MongoDB, Python, Ruby... for Windows.
Devserver installs a complete and ready-to-use development environment. Devserver is portable, modular, fully configurable and easy to update and extend.
Webserver turns your computer into a ready-to-use personal web hosting server. You can host whatever you want directly on your computer and share it on internet like any website. Your computer acts like a web hosting service and allows you to make your website / application / demo accessible via internet. The server is fully configurable, modular and easy to update and extend.

Convert special character to normal PHP function


Convert special character to normal PHP function:

function convertSpecialToNormal($string) {
$table = array('À'=>'A', 'Á'=>'A', 'Â'=>'A', 'Ã'=>'A', 'Ä'=>'A', 'Å'=>'A', 'A'=>'A', 'A'=>'A', 'A'=>'A', 'Æ'=>'A', '?'=>'A','à'=>'a', 'á'=>'a', 'â'=>'a', 'ã'=>'a', 'ä'=>'a', 'å'=>'a', 'a'=>'a', 'a'=>'a', 'a'=>'a', 'æ'=>'a', '?'=>'a','Þ'=>'B', 'þ'=>'b', 'ß'=>'Ss','Ç'=>'C', 'C'=>'C', 'C'=>'C', 'C'=>'C', 'C'=>'C','ç'=>'c', 'c'=>'c', 'c'=>'c', 'c'=>'c', 'c'=>'c','Ð'=>'Dj', 'D'=>'D', 'Ð'=>'D','d'=>'dj', 'd'=>'d','È'=>'E', 'É'=>'E', 'Ê'=>'E', 'Ë'=>'E', 'E'=>'E', 'E'=>'E', 'E'=>'E', 'E'=>'E','è'=>'e', 'é'=>'e', 'ê'=>'e', 'ë'=>'e', 'e'=>'e', 'e'=>'e', 'e'=>'e', 'e'=>'e','G'=>'G', 'G'=>'G', 'G'=>'G', 'G'=>'G','g'=>'g', 'g'=>'g', 'g'=>'g', 'g'=>'g','H'=>'H', 'H'=>'H','h'=>'h', 'h'=>'h','Ì'=>'I', 'Í'=>'I', 'Î'=>'I', 'Ï'=>'I', 'I'=>'I', 'I'=>'I', 'I'=>'I', 'I'=>'I', 'I'=>'I','ì'=>'i', 'í'=>'i', 'î'=>'i', 'ï'=>'i', 'i'=>'i', 'i'=>'i', 'i'=>'i', 'i'=>'i', 'i'=>'i','J'=>'J','j'=>'j','K'=>'K','k'=>'k', '?'=>'k','L'=>'L', 'L'=>'L', 'L'=>'L', '?'=>'L', 'L'=>'L','l'=>'l', 'l'=>'l', 'l'=>'l', '?'=>'l', 'l'=>'l','Ñ'=>'N', 'N'=>'N', 'N'=>'N', 'N'=>'N', '?'=>'N','ñ'=>'n', 'n'=>'n', 'n'=>'n', 'n'=>'n', '?'=>'n', '?'=>'n','Ò'=>'O', 'Ó'=>'O', 'Ô'=>'O', 'Õ'=>'O', 'Ö'=>'O', 'Ø'=>'O', 'O'=>'O', 'O'=>'O', 'O'=>'O', 'Œ'=>'O','ò'=>'o', 'ó'=>'o', 'ô'=>'o', 'õ'=>'o', 'ö'=>'o', 'ø'=>'o', 'o'=>'o', 'o'=>'o', 'o'=>'o', 'œ'=>'o', 'ð'=>'o','R'=>'R', 'R'=>'R','r'=>'r', 'r'=>'r', 'r'=>'r','Š'=>'S', 'S'=>'S', 'S'=>'S', 'S'=>'S','š'=>'s', 's'=>'s', 's'=>'s', 's'=>'s','T'=>'T', 'T'=>'T', 'T'=>'T','t'=>'t', 't'=>'t', 't'=>'t','Ù'=>'U', 'Ú'=>'U', 'Û'=>'U', 'Ü'=>'U', 'U'=>'U', 'U'=>'U', 'U'=>'U', 'U'=>'U', 'U'=>'U', 'U'=>'U','ù'=>'u', 'ú'=>'u', 'û'=>'u', 'ü'=>'u', 'u'=>'u', 'u'=>'u', 'u'=>'u', 'u'=>'u', 'u'=>'u', 'u'=>'u','W'=>'W', '?'=>'W', '?'=>'W', '?'=>'W','w'=>'w', '?'=>'w', '?'=>'w', '?'=>'w','Ý'=>'Y', 'Ÿ'=>'Y', 'Y'=>'Y','ý'=>'y', 'ÿ'=>'y', 'y'=>'y','Ž'=>'Z', 'Z'=>'Z', 'Z'=>'Z', 'Ž'=>'Z','ž'=>'z', 'z'=>'z', 'z'=>'z', 'ž'=>'z','“'=>'', '”'=>'', '"'=>"",'‘'=>"", '’'=>"", '•'=>'-', '…'=>'...', '—'=>'-', '–'=>'-', '¿'=>'?', '¡'=>'!', '°'=>' degrees ','¼'=>' 1/4 ', '½'=>' 1/2 ', '¾'=>' 3/4 ', '?'=>' 1/3 ', '?'=>' 2/3 ', '?'=>' 1/8 ', '?'=>' 3/8 ', '?'=>' 5/8 ', '?'=>' 7/8 ','÷'=>' divided by ', '×'=>' times ', '±'=>' plus-minus ', 'v'=>' square root ', '8'=>' infinity ','˜'=>' almost equal to ', '?'=>' not equal to ', '='=>' identical to ', '='=>' less than or equal to ', '='=>' greater than or equal to ','?'=>' left ', '?'=>' right ', '?'=>' up ', '?'=>' down ', '?'=>' left and right ', '?'=>' up and down ','?'=>' care of ', 'e' => ' estimated ','O'=>' ohm ','?'=>' female ', '?'=>' male ','©'=>' Copyright ', '®'=>' Registered ', '™' =>' Trademark ',);

    $string = strtr($string, $table);
    $string = preg_replace("/[^\x9\xA\xD\x20-\x7F]/u", "", $string);
    return $string;
}

Example:




$string = "This is  tést";
$converted = convertSpecialToNormal($string);

echo "Orginal string: ".$string;
echo "<br>";

echo "Converted string: ".$converted;

Move all file from a folder to another PHP

// Get array of all source files into source_folder
$files = scandir("source_folder");

// Identify directories inside source_folder
$source = "source_folder/";
$destination = "destination_folder/";

// Cycle through all source files
foreach ($files as $file) {
  if (in_array($file, array(".",".."))) continue;
  // If we copied this successfully, mark it for deletion
  if (copy($source.$file, $destination.$file)) {
    $delete[] = $source.$file;
  }
}
// Delete all successfully-copied files
foreach ($delete as $file) {
  unlink($file);

}

If we want to copy all files from a folder to another follow this URL; http://programming-scripts.blogspot.com/2017/01/copy-all-file-from-folder-to-another-php.html

Copy all file from a folder to another PHP





// Get array of all source files into source_folder
$files = scandir("source_folder");

// Identify directories inside source_folder
$source = "source_folder/";
$destination = "destination_folder/";

// Cycle through all source files
foreach ($files as $file) {
  if (in_array($file, array(".",".."))) continue;
      copy($source.$file, $destination.$file);
  }
}


If we want to transfer all files from a folder to another follow this URL: http://programming-scripts.blogspot.com/2017/01/move-all-file-from-folder-to-another-php.html