View tutorial-code.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require dirname(__FILE__).'/smtp-validate-email.php'; | |
$from = 'your@emailaddress.com'; | |
if (!$db = new mysqli('localhost', 'username', 'password', 'databasename')) { | |
die('Can\'t connect to the database.'); | |
} else { | |
// after I imported all email addresses into the data I select 25 records for validation | |
$res = $db->query("SELECT ID, email FROM emailaddresses WHERE status = 'valid' ORDER BY RAND() LIMIT 25"); |
View FileCache.class.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class FileCache { | |
protected $cacheValidTime; | |
public $cacheIsValid = false; | |
protected $cacheFile; | |
function __construct($file, $valid = 86400) { | |
$this->setCacheFile($file); |
View PHP-Filesize-with-label.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function file_size($file, $path = "") { | |
define("DOCUMENT_ROOT", dirname(__FILE__); // better you define this in the root | |
$bytes = array("B", "KB", "MB", "GB", "TB", "PB"); | |
$file_with_path = DOCUMENT_ROOT."/".$path."/".$file; | |
// replace (possible) double slashes with a single one | |
$file_with_path = str_replace("//", "/", $file_with_path); | |
$size = filesize($file_with_path); | |
$i = 0; | |
while ($size >= 1024) { //divide the filesize (in bytes) with 1024 to get "bigger" bytes |
View PHP-local-date-notations.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class local_date { | |
private $week_day; | |
private $day; | |
private $month; | |
private $year; | |
public function __construct() { | |
$this->week_day = date("l"); |
View create-radio-group.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$values = array('google'=>'Google Search', 'link'=>'Link on some website', 'advert'=>'Advertisement', 'news'=>'News'); | |
$html_elements = array('before'=>'<span>', 'after'=>'</span><br />', 'label'=>'<label for="test"><b>Some label</b></label><br />'); | |
function dynamic_radio_group($formelement, $values, $html, $def_value = '') { | |
$radio_group = '<div>'."\n"; | |
$radio_group .= (!empty($html['label'])) ? $html['label']."\n" : ''; | |
if (isset($_REQUEST[$formelement])) { | |
$curr_val = stripslashes($_REQUEST[$formelement]); |
View select-with-optgroup.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// First you need some code to get a database result set. | |
// Split the resultset into two arrays, one for the product groups and one for the categories. | |
$sql = "SELECT id, parent_id, name, var_name FROM prod_category ORDER BY parent_id, id ASC"; $categories = mysql_query($sql); | |
while ($obj = mysql_fetch_object($categories)) { | |
if (!empty($obj->parent_id)) { // there are options | |
$arr_options[$obj->id]['parent'] = $obj->parent_id; // the corresponding key (group id) | |
$arr_options[$obj->id]['label'] = $obj->name; | |
$arr_options[$obj->id]['value'] = $obj->var_name; | |
// this array is build to check later the existings of options against the option groups |
View create-form-fields.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function create_form_field($formelement, $label = "", $db_value = "", $length = 25) { | |
$form_field = ($label != "") ? "<label for=\"".$formelement."\">".$label."</label>\n" : ""; | |
$form_field .= " <input name=\"".$formelement."\" type=\"text\" size=\"".$length."\" value=\""; | |
if (isset($_REQUEST[$formelement])) { | |
$form_field .= $_REQUEST[$formelement]; | |
} elseif (isset($db_value) && !isset($_REQUEST[$formelement])) { | |
$form_field .= $db_value; | |
} else { | |
$form_field .= ""; |
View extract-tld-from-domain.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$url_parts = parse_url("http://mail.finalwebsites.co.uk"); | |
$domain = $url_parts['host']; | |
$db = new mysqli(DB_SERVER, DB_USER, DB_PASSWORD, DB_NAME); | |
$res = $db->query("SELECT tld FROM domain_info ORDER BY LENGTH(tld) DESC"); | |
// "ORDER BY LENGTH(tld)" will give first the co.uk and then the uk | |
while ($arr = $res->fetch_array(MYSQLI_ASSOC)) { | |
$tmp_tld = substr($domain, -strlen(".".$arr['tld'])); | |
if ($tmp_tld == ".".$arr['tld']) { // You found the tld | |
$tld = ltrim($arr['tld'], "."); |
OlderNewer