Skip to content

Instantly share code, notes, and snippets.

View nagiyevelchin's full-sized avatar
🌴
On vacation

Elchin Nagiyev nagiyevelchin

🌴
On vacation
View GitHub Profile
@nagiyevelchin
nagiyevelchin / deleteDirectory.php
Last active October 7, 2023 11:10
Efficient PHP Function for Deleting Directories and Their Contents
<?php
/**
* Efficient PHP Function for Deleting Directories and Their Contents
*
* This PHP function, named 'deleteDirectory,' is designed to safely and
* efficiently delete directories and all their contents. It first checks if
* the directory exists, and if not, it returns 'true' since the directory is
* already deleted. Next, it determines whether the specified path is a directory
* or a symbolic link and unlinks it if necessary.
@nagiyevelchin
nagiyevelchin / generatePassword.php
Last active February 12, 2022 15:56
Generate complex random password in PHP
<?php
/**
* Generate random password
* @param int $length [optional] [default 9] length password to be generated
* @return string
* @link http://www.webtoolkit.info/php-random-password-generator.html
* @since 12/1/12 11:30 AM
*/
function generatePassword($length = 9) {
$vowels = 'aeuy';
@nagiyevelchin
nagiyevelchin / validEmail.php
Last active February 12, 2022 15:56
Validate an email address in PHP
<?php
/**
* Validate an email address.
* Provide email address (raw input)
* Returns 1 if the email address has the email
* address format and the domain exists.
*/
function validEmail($email) {
$isValid = 1;
$atIndex = strrpos($email, "@");
@nagiyevelchin
nagiyevelchin / subStringByLastNBSP.php
Last active October 7, 2023 11:34
This PHP function, subStringByLastNBSP, is designed to extract a substring from a given input string while ensuring that the resulting substring does not exceed a specified maximum length ($max). It also considers a minimum length ($min) that the substring should have before attempting to find the last non-breaking space character (' ') within t…
<?php
/**
* Extracts a substring from a given string, ensuring it does not exceed a maximum length,
* and ends at the last occurrence of a non-breaking space character (' ') within the specified range.
*
* @param string $string The input string to extract the substring from.
* @param int $max The maximum length of the substring.
* @param int $min The minimum length of the substring before considering the last non-breaking space.
* @param string $endstring Optional: The string to append to the extracted substring.
*
@nagiyevelchin
nagiyevelchin / truncate.php
Last active February 12, 2022 16:00
Truncate a string to a certain length in PHP
<?php
/**
* Truncate a string to a certain length if necessary,
* optionally splitting in the middle of a word, and
* appending the $etc string or inserting $etc into the middle.
*
* @param string $string input string
* @param integer $length length of truncated text
* @param string $etc end string
* @param boolean $break_words truncate at word boundary
@nagiyevelchin
nagiyevelchin / mkdir.php
Last active February 12, 2022 15:59
Recursively create directory in PHP
<?php
/**
* Makes directory
* @link http://stackoverflow.com/questions/5425891/check-if-directory-exists-php
* @param string $pathname The directory path.
* @param int $mode [optional]<p>
* The mode is 0777 by default, which means the widest possible
* access. For more information on modes, read the details
* on the <b>chmod</b> page.
* </p>
@nagiyevelchin
nagiyevelchin / PHPMailGmail.php
Last active February 12, 2022 15:58
PHPMailer Gmail working example PHP
<?php
/**
* PHPMailer Gmail working example
*
* composer require phpmailer/phpmailer
*
*/
require 'autoload.php';
@nagiyevelchin
nagiyevelchin / ready.php
Last active July 11, 2019 10:57
ProcessWire multiple domain multiple language
<?php
//paste it in "site/ready.php" file
$wire->addHookAfter('Page::render', function (\ProcessWire\HookEvent $event) {
if (strpos(wire('config')->urls->httpRoot, '.com') !== false && wire('user')->language->name !== 'default') {
header("HTTP/1.1 301 Moved Permanently");
header("Location: ".wire('page')->localHttpUrl('default'));
exit();
} elseif (strpos(wire('config')->urls->httpRoot, '.ru') !== false && wire('user')->language->name !== 'ru') {
header("HTTP/1.1 301 Moved Permanently");
header("Location: ".wire('page')->localHttpUrl('ru'));
@nagiyevelchin
nagiyevelchin / PHPMailYandex.php
Created July 12, 2019 06:53
PHPMail Yandex send through smtp and save sent mail in imap folder
<?php
print "<pre>";
$mbox = imap_open("{imap.yandex.ru}/ONE", "***@yandex.ru", "****", OP_HALFOPEN)
or die("can't connect: " . imap_last_error());
$list = imap_getmailboxes($mbox, "{imap.yandex.ru}", "*");
if (is_array($list)) {
print_r($list);
} else {
echo "imap_getmailboxes failed: " . imap_last_error() . "\n";
}
@nagiyevelchin
nagiyevelchin / image-resize.js
Created September 1, 2019 12:52
Resizing image in user side in Vue CLI JavaScript
/**
* Resizing image in user side
* @param {string} filePath - file input value
* @param {number} [max_width=1600] - result image max width
* @param {number} [max_height=900] - result image max height
* @returns {Promise<base64string>}
*/
export default (filePath, max_width, max_height) => {
/**
* Example