PHP

PHP Fatal error: Class ‘DOMDocument’ not found

When setting up applications such as Magento you may come across the error message “PHP Fatal error: Class ‘DOMDocument’ not found …” in your apache server log files

Reason for the error is missing log files. Issue the commands below to fix the issue

$ yum -y install php-xml php-devel

$ service httpd reload

Share it onShare on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn

How to setup, install Apache, PHP and MySQL on Mac OS?

Apache server is installed by default on Mac. Access the configuration settings for Apache by going to

$ cd /etc/apache2/
$ vi httpd.conf

To enable php, edit httpd.conf and uncomment the line
#LoadModule php5_module libexec/apache2/libphp5.so

Uncomment other lines that you may want to load in your system. As you are enabling PHP in your system, you may want to change the DirectoryIndex to
DirectoryIndex index.php index.html

Default group/user settings inside Apache on Mac is _www:_www
Continue Reading…

Share it onShare on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn

PHP Excel reader

php-excel-reader Parse and retrieve information from XLS files

Download from Code Google

When the excel reader is run on PHP 5.3, below mentioned deprecated warning messages gets shown.

i) Assigning the return value of new by reference is deprecated

Remove & from the line below

$this->_ole =& new OLERead();

and have

$this->_ole = new OLERead();

instead.

ii) Function split() is deprecated

Function split() is deprecated and we can use explode() instead of that.

$parts = split(“;”,$format);

change it to

$parts = explode(“;”,$format);

Share it onShare on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn

PHP: ‘Fatal error: Allowed memory size of 8388608 bytes exhausted’

Reason why you see this message is due to PHP memory leakage. PHP is trying to load a large image or file into memory and is not finding enough space for it to load.

If you think, that you will need the necessary feature to upload large files then there are two ways by which you can enable this feature.

i) Edit the physical file and have the line
ini_set(“memory_limit”,”20M”);

ii) Edit php.ini and add the following line. You need to restart the apache/IIS server once php.ini file is modified.
memory_limit=32M

Share it onShare on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn

UTF and Byte Order Mark (BOM)

UTF abbr. Unicode Transformation Format is a super set of characters that facilitates the display of characters from ALL languages that is currently in use.

BOM stands for Byte Order Mark (also known as ZERO WIDTH NON-BREAKING SPACE) appearing at the beginning of a data stream to define the byte order (whether it is little endian or big endian). BOM is to indicate that the file is Unicode based.

Possible problem caused by Byte Order Mark
In IE6, it will send the dispaly into quirks mode with its presence before “<DOCTYPE …”

How to check the presence of BOM?
View the source code of the page that does not display correctly in a user agent. Or, open the file in the editor which does not support UTF encoding to see the BOM’s signature on the files.

Suggestion
If the user-agent gives problem when you program for multi-lingual websites, check the editor settings to see what format is being used for saving program files. Notepad++ has the option to convert files to UTF and to UTF without BOM. Use the appropriate settings to convert your files.

A character set related tutorial on W3C site can be found here

Byte Order Mark on Wiki

Article on PHP and UTF

Share it onShare on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn

PHP: Parse URL encoded GET data

<?php
// To build back the URI and to extract the passed parameters, you can use parse_url, parse_string function 
$extract_string = parse_url($pass_string);
echo "<h2>Extracted URI (using parse_url)</h2><br />";
echo "<pre>";
var_dump($extract_string);
echo "</pre>";

// To decode the query string use parse_str function 
parse_str($extract_string["query"], $extract_query);
echo "<h2>Extracted Query String (using parse_str)</h2><br />";
echo "<pre>";
var_dump($extract_query);
echo "</pre>"; 

?>
Share it onShare on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn

PHP: Program to pass data using character encoding (GET Parameter)

PHP program to pass data as GET parameters

<?php
// PHP 5 how to pass data as a query string
/*
http_build_query is a function in PHP 5 that enables you to URL encode the query string. You can pass an array or an array of array to this function. The default separator is "&"
*/

$data = array("first_name" => "Robert",
                "last_name" => "Brown",
                "address" => "123 Adam St., New York"
            );

// URI formatted with character encoding
$pass_string = "http://localhost/demo.php?".http_build_query($data, '');

echo "<h2>Query URI (using http_build_query)</h2><br />";
echo $pass_string;            
?>

Ouput from the above execution:
Query URI (using http_build_query)
http://localhost/demo.php?first_name=Robert&last_name=Brown&address=123+Adam+St.%2C+New+York

Share it onShare on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn

PHP: How to receive the posted XML data?

Receive the posted XML data

In order to test the posted data, we can create a file creation steps to ensure that we receive the posted data via the $_POST array

<?php
/* 
  File name: postdata2.php
*/
    $xmlFile = "xmlFile.txt";
    $fh = fopen($xmlFile, 'w') or die("Cannot open file");
    fwrite($fh, $_POST["xmldata"]);
    fclose($fh);



?>
Share it onShare on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn

PHP removing deprecated related errors from display

To remove deprecated warning message displays when executing PHP programs, open php.ini file and ADD to it

error_reporting = E_ALL & ~E_DEPRECATED

This is the setting for the production environment where you would not like to display the deprecated function related errors.

Sample error message
Assigning the return value of new by reference is deprecated in nusoap.php on line 7381

Share it onShare on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn

CakePHP: Multi-validatable Behavior

Consider the following scenario where we have a database table:users and that we need carry the validations for the following forms
i) Login
ii) Change password
iii) Add/Edit user records
iv) Forgot password

You can either write separate controllers and have each controller call a model based on table: users to validate each input field or use the same user model to carry out different validations which sounds logical.

It is easy to carry out different validations in a cakephp model by using the Multi-validatable Behavior by having different validation sets for different testing conditions.

Key things to note here …

i) Download the code for Multivalidatable Behavior and have it placed under /models/behaviors/ folder

ii) In the model where you want to have multi validation, you need to include multivalidatable behavior like
var $actsAs = array(“Multivalidatable”);

iii) Add validation rulesets array like
var $validationSets = array(‘login’ => array(‘name’=>array(‘rule’=>’alphanumeric’)),
‘changepassword’ => array(‘password’=>array(‘rule’=>’notEmpty’))
);

iv) In the controller where you want to apply the validation rule set, you need to add the respective validation like

function login(){
$this->User->setValidation(‘login’);
}

function changepassword(){
$this->User->setValidation(‘changepassword’);
}

For more info visit CakePHP Bakery

Share it onShare on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn
Kurinchi Calendar
May 2017
M T W T F S S
« Apr    
1234567
891011121314
15161718192021
22232425262728
293031