While working on different personal websites I noticed that I always need same kind of PHP functions (truncate text, resize images, etc) so I decided to keep a centralised location for them.
Many of them might need work, so feel free to improve/comment/etc.
Thanks.
Download file tnt_php_functions.php and include it in your php file with:
include("tnt_php_functions.php");
Then inside your call any of the included functions:
remove_var_from_url("a", "script.php?a=1&b=2");
(will return script.php?b=2
).
get_url();
tnt_post_url('script.php', $post_data_array);
add_var_to_url($variable_name,$variable_value,$url_string);
Print a time like "10 seconds ago", "3 days ago", "2 years ago" out of a timestamp like 1490279856
timestamp_to_ago(1490279856);
Time how long different operations took on your website/script, get a timer for each, output is an array of all timers you used.
Note that you can define more than one timer in your code, how long it takes to load users from db, how long it takes to then loop over an array of users, etc.
// start a timer
timer("my db query");
// put some code here that loads users from database
// call again to stop a timer
timer("my db query");
// prints total seconds: 0.123
echo $timer["my db query"];