Skip to content

Instantly share code, notes, and snippets.

View umidjons's full-sized avatar
🏠
Working from home

Umid umidjons

🏠
Working from home
View GitHub Profile
@umidjons
umidjons / replace_multi_space_one.php
Created July 14, 2013 06:06
Replace multiple spaces with one using preg_replace()
<?php
$str = preg_replace('/\s\s+/u', ' ', $str); // no issue with cyrillic letters, because using "u" modifier for UTF-8
@umidjons
umidjons / clean_non_number.php
Last active December 19, 2015 19:38
Clean & convert value from non numeric characters
<?
// clean $field value from non numeric characters
$field = "234.345g";
echo $field . '<br>'; // 234.345g
$fieldFloat = floatval( preg_replace( '/[^-0-9\.]/', "", $field ) ); // 234.345
$fieldInt = intval( preg_replace( '/[^-0-9]/', "", $field ) ); // 234
echo $fieldFloat . '<br>';
echo $fieldInt . '<br>';
?>
@umidjons
umidjons / bx_send_mail.php
Created July 17, 2013 04:29
Send mail in Bitrix example.
<?
// Настройки продукта / Почтовые события / Типы почтовых событий
// создаем новый тип почтового события MY_NEW_MAIL_EVENT
$mailFields[ "EMAIL_FROM" ] = "[email protected]";
$mailFields[ "EMAIL_TO" ] = "[email protected],[email protected]";
$mailFields[ "PROP_SOME_VALUE" ] = 'some text is here';
$mailFields[ "PROP_OTHER_VALUE" ] = 'some other text is here';
// Создаем новый почтовый шаблон.
@umidjons
umidjons / bx-left-menu.php
Created July 18, 2013 07:12
Manage access to menu items in Bitrix
<?php
$aMenuLinks = Array(
Array(
"Accessible by all",
"/path/page1/",
Array(),
Array(),
"",
),
Array(
@umidjons
umidjons / .htaccess
Created July 18, 2013 09:43
Set Charset in Apache configuration file (.htaccess)
AddDefaultCharset utf-8
@umidjons
umidjons / split_by_eol.php
Created July 18, 2013 10:20
Split text by EOL with preg_split()
<?php
$arLines = preg_split( '/\r?\n/i', trim( $longText ) );
@umidjons
umidjons / whole-height.css
Created July 18, 2013 16:22
Make div 100% of browser window
body,html {
height: 100%;
}
div#mydiv {
height: 100%
}
@umidjons
umidjons / cycle.test.html
Last active December 19, 2015 23:49
Cycle Slider Test
<html>
<head>
<title>Test</title>
<style>
html,body{
width: 100%;
height: 100%;
margin: 0;
padding: 0;
@umidjons
umidjons / wp-custom-image-size.php
Created July 20, 2013 14:10
Custom size for featured image in wordpress
<?php
// in functions.php
function my_theme_setup()
{
add_image_size('my-thumbnail', 310, 160);
}
add_action( 'after_theme_setup', 'my_theme_setup' );
?>
<?php
@umidjons
umidjons / test_tz.php
Last active December 20, 2015 07:29
Changing Timezone in php.ini
<?php
echo "TimeZone: " . date_default_timezone_get();
echo " Current date and time: " . date( 'Y-m-d H:i:s' );
// We also can set timezone at runtime
// date_default_timezone_set('America/Los_Angeles');
?>