Skip to content

Instantly share code, notes, and snippets.

@gartes
Last active June 26, 2020 11:12
Show Gist options
  • Save gartes/934e44a30a3ffe3ae084fb819cb75e78 to your computer and use it in GitHub Desktop.
Save gartes/934e44a30a3ffe3ae084fb819cb75e78 to your computer and use it in GitHub Desktop.

https://gist.github.com/gartes/934e44a30a3ffe3ae084fb819cb75e78

  1. Ссылки

[Проверить строку на домен]

$href = 'https://joomla-upd.ga/test_css/test_home.css' ;  // True
$href = '//joomla-upd.ga/test_css/test_home.css' ;  // False
if(preg_match('/^(https?:\/\/)/', $href)){
	echo true ;
}

[Проверить URL на внешний домен]

$href = 'https://joomla-upd.ga/test_css/test_home.css' ;  // True
$href = '//joomla-upd.ga/test_css/test_home.css' ;  // True

$protocol = parse_url( $href  );
if( !isset( $protocol[ 'host' ] ) ) return false;
if( !stristr( \JURI::root() , $protocol[ 'host' ] ) ) return true;
return false;

Замена двойных кавычек “умными” кавычками

Если вы любитель типографики, вам понравится это регулярное выражение, заменяющее обычные двойные кавычки, на “умные кавычки”. Похожее регулярное выражение используется в wordpress в контенте страницы.

preg_replace('B"b([^"x84x93x94rn]+)b"B', '?1?', $text);

Удалить все кроме чисел

$item = preg_replace("/[^0-9]/", "",$item) ;

Проверить на наличие пробела в строке

<?php preg_match( '/\s/', $href ); ?>

Проверить на русские символы

<?php
if( !preg_match("/^[а-яА-Я]+$/iu", $author) )
    echo("разрешено вводить только русские буквы!");
?>

[Ссылки]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment