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 convertBytes(int $bytes, string $convert_to = 'KB', bool $format = true, int $decimals = 2): float | |
{ | |
if ($convert_to == 'KB') { | |
$value = ($bytes / 1024); | |
} elseif ($convert_to == 'MB') { | |
$value = ($bytes / 1048576); | |
} elseif ($convert_to == 'GB') { | |
$value = ($bytes / 1073741824); | |
} elseif ($convert_to == 'TB') { |
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 getVideoDetails(string $media_link): array | |
{ | |
$data = json_decode(shell_exec("ffprobe -v quiet -print_format json -show_format -show_streams '$media_link'"), true); | |
if (isset($data['streams'])) {//Data exists, video file is readable | |
$first_stream = $data['streams'][0]; | |
$video_codec = $first_stream['codec_name']; | |
$video_width = $first_stream['width'];//Video width | |
$video_height = $first_stream['height'];//Video height | |
$fr_array = explode('/', $first_stream['r_frame_rate']);//Splits frame rate string into array 60/1 -> 60,1 |
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 getAspectRatio(int $width, int $height): string | |
{ | |
$ratio_value = ($width / $height); | |
if ($ratio_value == 1.000) { | |
$ratio_string = '1:1'; | |
} elseif ($ratio_value == 1.250) { | |
$ratio_string = '5:4'; | |
} elseif ($ratio_value == 1.333) { | |
$ratio_string = '4: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 intCompare(int $value1, int $value2): array | |
{ | |
if ($value1 > $value2) {//value1 is bigger than value2 | |
$one_is_greater = true; | |
$symbol = '+'; | |
} else { | |
$one_is_greater = false; | |
$symbol = '-'; | |
} |
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 stringLengthCheck(string $string, int $min, int $max): bool | |
{ | |
if (strlen($string) >= $min && strlen($string) <= $max) { | |
return true; | |
} else { | |
return false; | |
} | |
} |
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 stringContains(string $string, string $needle): bool | |
{ | |
if (strpos($string, $needle) !== false) { | |
return true; | |
} else { | |
return false; | |
} | |
} |
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') { |
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
<style> | |
body { | |
background: #0d161f; | |
} | |
.row { | |
background: #00b9eb; | |
padding: .4rem; | |
margin-top: .6rem; | |
text-align: center; | |
} |
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 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 |