Minus one month date
Minus one month date
"Minus one month" date:
<?php $yesterday = date('Y-m-d', mktime(0, 0, 0, date("m") - 1 , date("d"), date("Y"))); ?>
Get last inserted id SQL
$sql = "INSERT INTO `myTable` ( `id` , `name` )VALUES ( NULL, 'test');";
execute query and then:
$lastInsertedId = mysqlid(connectName);
Write text ovear an image png - php
run time change register_globals to ON via .htaccess
- create file .htaccess
- include this line : php_flag register_globals 1
check_email php function
function check_email($email_address) {
$pattern = "/^[\w-]+(\.[\w-]+)*@";
$pattern .= "([0-9a-z][0-9a-z-]*[0-9a-z]\. )+([a-z])$/i";
if (preg_match($pattern, $email_address)) {
$parts = explode("@", $email_address);
if (checkdnsrr($parts[1], "MX")){
return(1);
// return true;
} else {
return(0);
// return false;
}
} else {
return(0);
// return false;
}
}
google analytics auto login, login automatically into google account
<form style="visibility:hidden;" name="googleanalyticslogin" id="googleanalyticslogin" action="https://www.google.
<input type="text" name="Email" class="gaia le val" id="Email" size="18" value="myemail@gmail.com" />
<input type="password" name="Passwd" class="gaia le val" id="Passwd" size="18" value="myGooglePassword" />
<input type="checkbox" name="PersistentCookie" value="yes" />
<input type="hidden" name="rmShown" value="1" />
<input type="hidden" name="continue" value="http://www.google.com/
<input type="hidden" name="service" value="analytics" />
<input type="hidden" name="nui" value="1" />
<input type="hidden" name="hl" value="en-US" />
<input type="hidden" name="GA3T" value="oCGYxIWWGUE" />
</form>
<IFRAME name="teste123" src="google.php" style="border:1px solid gray; width:100%; height:600px;">
Xml to array function
function xml2array($xml) {
$xmlary = array();
$reels = '/<(\w+)\s*([^\/>]*)\s*(?:\/>|
$reattrs = '/(\w+)=(?:"|\')([^"\']*)(:?"|
preg_match_all($reels, $xml, $elements);
foreach ($elements[1] as $ie => $xx) {
$xmlary[$elements[1][$ie]] = $elements[3][$ie];
$res = $this->xml2array($elements[3][
if($res)
$xmlary[$elements[1][$ie]] = $res;
}
return $xmlary;
}
Write array to xml file
<?
function arrayToXml($myArrays, $filePath=""){
$xmlContent = '<?xml version="1.0" encoding="ISO-8859-1" ?>';
$xmlContent .= "\n<students>";
foreach($myArrays as $myArray){
$xmlContent.= "\n <student>";
foreach($myArray as $key=>$value){
$xmlContent.="\n <$key>$value</$key>";
}
$xmlContent .= "\n </student>";
}
$xmlContent .= "\n</students>";
if($filePath){
$fh = fopen($filePath, 'w') or die("Can't open file");
fwrite($fh, $xmlContent);
fclose($fh);
}
return $xmlContent;
}
//USE CASE
$students[0] = array("name"=>"John", "age"=>"32");
$students[1] = array("name"=>"Maria", "age"=>"42");
header ("content-type: text/xml");
echo arrayToXml($students);
?>
array2csv - php
<?php
// # # # # # # # # # # # # # # # # # # # # # # # # #
// file_name, download_mode (0 (silence), 1(print) or 2(return link))
// # # # # # # # # # # # # # # # # # # # # # # # # #
function createCSV($csv_name, $download) {
$i = 1;
$csv = "";
$csvPath="";
/* erase the old file, if it exists */
@unlink($csvPath . $csv_name . ".csv");
$my_array = $_SESSION['my_array'];
$fields = count(array_keys($my_array[0]));
/* extracting the titles from the array */
foreach(array_keys($my_array[0]) as $title){
/* array_keys percurs the title of each vector */
$csv .= $title;
/* while it is not the last field put a semi-colon ; */
if($i < $fields)
$csv .= ";";
$i++;
}
$csv .= chr(10).chr(13);
/* get the values from the extracted keys */
foreach (array_keys($my_array) as $tipo){
$i = 1;
foreach(array_keys($my_array[$tipo]) as $sub){
$csv .= $my_array[$tipo][$sub];
if ($i < $fields)
$csv .= ";";
$i++;
}
$csv .= chr(10).chr(13);
}
/* export the csv */
$export_csv=fopen($csvPath. $csv_name .".csv", "w+");
fwrite($export_csv, $csv);
fclose($export_csv);
/* download the csv */
if ($download == 1)
header('Location:' . $csvPath . $csv_name . ".csv");
if ($download == 2)
return ($csvPath . $csv_name . ".csv");
return;
}
?>
PHP - Force a page to go on https
if ($_SERVER['HTTPS']!='on')
header("location: https://".$_SERVER[HTTP_HOST].$_SERVER[REQUEST_URI]);
PHP - Debug error reporterror_reporting(E_ALL);PHP - Parse html tags
$data = file_get_contents("http://www.finalwebsites.com"); $pattern = "/src=[\\"']?([^\\"']?.*(png| jpg|gif))[\\"']?/i"; preg_match_all($pattern, $data, $images);
MYSQL - Increment while update SET @temp =1;
UPDATE myTable SET myField = @temp := ( @temp +1 );
MYSQL - Nested Select (IN) select * FROM table where id IN (SELECT id FROM table2 where lang='eu')
SHELL SCRIPT - Sync Directories rsync -a -e ssh /home/myusername/Desktop/company/framework/ carlos@192.168.1.10:/home
/myfriendusername/Desktop/company/framework/
JAVASCRIPT - Prevent browser window to close
window.onbeforeunload= function (evt) { if (quit()) { //do your actions, even launch xmlhttprequest } } function quit() { if confirm("Quitter ?") { return true; } else { return false; }