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 outputString(string $string) | |
{ | |
echo $string; | |
} | |
function tableBuilder(array $theads, array $data, string $table_class = 'table', string $thead_class = '') | |
{ | |
(empty($table_class)) ? $tbl = "" : $tbl = " class='$table_class'"; | |
(empty($thead_class)) ? $th = "" : $th = " class='$thead_class'"; |
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 MysqlPageSystem(int $page_number, int $items_per_page) | |
{ | |
if ($page_number == 0) { | |
$start_at = 0;//Items 0 to $items_per_page | |
} else { | |
$start_at = ($page_number * $items_per_page);//Assume itemsPP = 4. For Page 2 (1*4) so it shows items 4 to 8 | |
//For Page 3 (?page=2) equation is (2*4) so page=2 will show items 8 to 12 | |
} |
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 doFTP | |
{ | |
public string $hostname = '111.222.33.4'; | |
public string $username = 'ftp_user'; | |
public string $password = '9dgVGOI6dG'; | |
public bool $passive_mode = true; | |
public function setDetails(string $hostname, string $username, string $password, bool $passive_mode) |
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 timeToSeconds(string $time): int | |
{ | |
$arr = explode(':', $time); | |
return $arr[0] * 3600 + $arr[1] * 60 + $arr[2]; | |
} | |
function duration(string $start, string $end): string | |
{ | |
$length = (timeToSeconds($start) - timeToSeconds($end)); |
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 timeToSeconds(string $time): int | |
{ | |
$arr = explode(':', $time); | |
if (count($arr) == 3) { | |
return $arr[0] * 3600 + $arr[1] * 60 + $arr[2]; | |
} else { | |
return $arr[1] * 60 + $arr[3]; | |
} | |
} |
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 idForLabel(string $label, array $instance_data) | |
{ | |
foreach ($instance_data['instances'] as $instance) { | |
if ($instance['label'] == $label) { | |
return array('found' => true, 'id' => $instance['id'], 'searchLabel' => $label); | |
} | |
} | |
return array('found' => false, 'searchLabel' => $label); | |
} |
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 | |
if (isset($_POST)) { | |
$data = ''; | |
foreach ($_POST as $input) { | |
$data .= $input . ' '; | |
} | |
$fp = fopen("formtestoutput.txt", "w"); | |
fwrite($fp, $data); | |
fclose($fp); | |
} |
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 randomTimeFormatted(string $max_time): string | |
{ | |
$t = explode(':', $max_time); | |
return sprintf("%02d:%02d:%02d", rand(0, $t[0]), rand(0, $t[1]), rand(0, $t[2])); | |
} | |
echo randomTimeFormatted('02:38:55'); | |
//02:38:55 will make random string from 0->2 hours, 0->38 mins, 0->55 seconds |
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 sitemapBuilder | |
{ | |
private function db_connect(): object | |
{ | |
$host = '127.0.0.1'; | |
$db_name = 'sitemap'; | |
$db_user = 'root'; | |
$db_password = ''; |
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 convertSize(float $size, string $convert_from = 'B', string $convert_to = 'KB', bool $format = true, int $decimals = 2): float | |
{ | |
$size = sprintf("%.2f", $size);//Int to float | |
if ($convert_from === 'B') { | |
if ($convert_to === 'KB') { | |
$value = ($size / 1024); | |
} elseif ($convert_to === 'MB') { | |
$value = ($size / 1048576); | |
} elseif ($convert_to === 'GB') { |