Get xml node attribute with PHP

$xml = simplexml_load_file(path/to/your/xml); // or simplexml_load_string('xml_string')
 
(string) $xml->your_node->attributes()->your_attribute;

Easy generate html forms with php

https://github.com/zech86/formx

Validate .xml with .xsd in php

$x_validate = new DOMDocument();
$x_validate->loadXML(xml_string); or $x_validate->load(path/to/file.xml);
 
// return bool
$x_validate->schemaValidate(path/to/xsd.xsd);

Install .deb package on terminal

sudo dpkg -i path/to/package.deb

Max days in a month with PHP

function get_max_days_in_month($month, $year) {
 
	$getdate = getdate(mktime(null, null, null, $month + 1, 0, $year));
 
	return $getdate['mday'];
}

Last weekday in a month with PHP

function get_last_weekday_in_month($month, $year) {
 
	$getdate = getdate(mktime(null, null, null, $month + 1, 0, $year));
 
	return $getdate['wday'];
}

First weekday in a month with PHP

function get_first_weekday_in_month($month, $year) {
 
	$getdate = getdate(mktime(null, null, null, $month, 1, $year));
 
	return $getdate['wday'];
}

chmod recursive

function chmod_r($path, $filemode) {
 
	if (!is_dir($path)) {
 
  		return chmod($path, $filemode);
 	}
 
 	$dh = opendir($path);
 
 	while ($file = readdir($dh)) {
 
	  if ($file != '.' && $file != '..') {
 
		$fullpath = $path.'/'.$file;
 
	   	if (!is_dir($fullpath)) {
 
	    		if (!chmod($fullpath, $filemode)) {
 
	     			return false;
	    		}
 
	   		} else {
 
	    		if (!chmod_r($fullpath, $filemode)) {
 
	     			return false;
	    		}
	   	}
	  }
	}
 
 	closedir($dh);
 
 	if (chmod($path, $filemode)) {
 
  		return true;
 	}
 
 	return false;
}

usage:

chmod_r('your/path', 0777);

zip files on terminal

zip -r /path/to/filename.zip /path/where/the/files/are/placed/

mysql foreign key check

turn off

SET FOREIGN_KEY_CHECKS=0;

turn on

SET FOREIGN_KEY_CHECKS=1;

ex.:

SET FOREIGN_KEY_CHECKS=0;
YOUR QUERY;
SET FOREIGN_KEY_CHECKS=1;
Page 8 of 10« First...678910