Skip to content

Instantly share code, notes, and snippets.

@anjan011
anjan011 / generate-url.php
Last active December 7, 2017 06:55
Generates an url
<?php
/**
* Generates an url
*
* @param array $params List of params
*
* @internal string $params['baseUrl'] The base url, default: $_SERVER['REQUEST_URI']
* @internal array $params['queryAdd'] Adds extra query params as associative array
* @internal array $params['queryRemove'] Removes query parameters as simple array
@anjan011
anjan011 / php-format-date.php
Created March 24, 2017 06:13
Changes the format of a given date/time string
<?php
/**
* Parses the given datetime string and changes it to the given format. This uses strtotime()
* to convert the datetime to timestamp, then changes format using date()
*
* @param string $dateStr String representing the datetime. If empty current datetime is used.
* @param string $format The desired format. Default: d/m/Y
* @param string $defaultIfInvalid A value to be returned if the given datetime is invalid
*
@anjan011
anjan011 / custom-radio-button-ui-using-css.html
Created December 3, 2016 17:38
Custom radio button skin using css only
<!doctype html>
<html lang="en">
<head>
<style type="text/css">
[type=radio] {
opacity: 0;
}
[type=radio] + label::before {
@anjan011
anjan011 / class-curl-fetch.php
Last active November 25, 2016 07:25
Class: CurlFetch - Simple class to fetch content from URL via GET or POST
<?php
/**
* Class CurlFetch
*
* A simple class to fetch content from an URL via GET or POST
*/
class CurlFetch {
@anjan011
anjan011 / php-url-generator.php
Created August 17, 2016 17:44
php url generator with query string modification
<?php
/**
* Class UrlGenerator
*
* A class to generate url, while adding or removing query string parameters
*/
class UrlGenerator {
@anjan011
anjan011 / mysql-sample-limit-clause.php
Created August 17, 2016 16:49
mysql sample limit clause generation
<?php
$pageNo = isset($limitParams['_ticketPage']) ? (int)$limitParams['_ticketPage'] : 1;
if($pageNo < 1) {
$pageNo = 1;
}
$recordsNo = isset($limitParams['_ticketRecords']) ? (int)$limitParams['_ticketRecords'] : 20;
@anjan011
anjan011 / format-datetime.php
Created July 12, 2016 07:39
Converts datetime string to given format
<?php
/**
* Convert date/time string to given format
*
* @param string $dateTimeString
* @param string $format
* @param string $noValueStr
*
* @return bool|string
*/
@anjan011
anjan011 / htaccess - redirect to https and www domain
Created June 29, 2016 12:35
htaccess - redirect to https and www domain
RewriteCond %{HTTPS} off
# First rewrite to HTTPS:
# Don't put www. here. If it is already there it will be included, if not
# the subsequent rule will catch it.
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Now, rewrite any request to the wrong domain to use www.
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
@anjan011
anjan011 / generate-hidden-inputs-from-array.php
Last active September 20, 2019 02:58
php: generate html hidden input elements from a php array
<?php
/**
* Convert an array of data into a list of html hidden input fields, using the
* array keys as name and values a input values.
*
* @param array $data Array of data
* @param string $namePrefix Name prefix for hidden controls
*
@anjan011
anjan011 / php-class-simple-pager.php
Last active August 17, 2016 07:55
php class: SimplePager
<?php
/**
* Created by PhpStorm.
* User: anjan
* Date: 9/30/15
* Time: 9:23 AM
*/
class SimplePager {