Regulérní výrazy regex nápady a šablony
regex for matching something if it is not preceded by something else
REGEX bude před použitím zřejmě nutno vložit mezi lomítka např. /regex/
Za ukončovací lomítka se dávají značky "flags" např. g - globální atd. viz v příspěvcích níže.
najde .round jen když není před ním Math
OK
a.round
c.round
NOT Math.round
regex if not followed by something
Vybere Math , za kterým NEnásleduje .round
OK
Math.pow, Math.cos
NOT
Math.round
Výše uvedené REGEX jsou vhodné například při hledání v souborech, kdy hledáme nějakou funkci stejného názvu, která není, nebo je přidružena např. k Math
REGEX bude před použitím zřejmě nutno vložit mezi lomítka např. /regex/
Za ukončovací lomítka se dávají značky "flags" např. g - globální atd. viz v příspěvcích níže.
(?<!Math)\.round
najde .round jen když není před ním Math
OK
a.round
c.round
NOT Math.round
regex if not followed by something
Math(?!\.round)
Vybere Math , za kterým NEnásleduje .round
OK
Math.pow, Math.cos
NOT
Math.round
Výše uvedené REGEX jsou vhodné například při hledání v souborech, kdy hledáme nějakou funkci stejného názvu, která není, nebo je přidružena např. k Math
77LW NO topic_id
AD
Další témata ....(Topics)
Php funkce, která vrátí string, jehož první písmeno bude změněno na velké a pracuje s diakritikou.
Pokud Vám PHP oznámí, že voláte neznámou funkci s prefixem mb_ tak je nutné přidat (odkomentovat) extension v php.ini
extension=php_mbstring.dll
Nutné je, aby jste upravili správný php.ini soubor, můžete jich míti více na disku a dále je nutné, aby jste měli příslušnou dll knihovnu v adresáři extension_dir
extension_dir = "C:\PHP\ext"
tedy php_mbstring.dll
Pokud Vám PHP oznámí, že voláte neznámou funkci s prefixem mb_ tak je nutné přidat (odkomentovat) extension v php.ini
extension=php_mbstring.dll
Nutné je, aby jste upravili správný php.ini soubor, můžete jich míti více na disku a dále je nutné, aby jste měli příslušnou dll knihovnu v adresáři extension_dir
extension_dir = "C:\PHP\ext"
tedy php_mbstring.dll
//////////////////////////////
function setFirstLetterToUpper($vstup)
{ // BEGIN function
if(mb_strlen($vstup)==1){
return mb_strtoupper($vstup);
}else if(mb_strlen($vstup)>1){
$upper = mb_strtoupper($vstup);
$vstup = mb_substr($upper, 0, 1).mb_substr($vstup,1,mb_strlen($vstup) - 1);
return $vstup;
}else
return $vstup;
} // END function
PHP formát datumu
Datum a čas v PHP
echo date('l jS of F Y h:i:s A');
// vypise neco podobneho: Saturday 21st of February 2009 11:38:59 AM
mktime()
strtotime()
time()
Y 4 číselný rok 2009
y 2 číselný rok 02
F celý měsíc February
M skratka měs Feb
m Měsíc (0 na počátku ) 01 do 12
n Měsíc 1 do 12
D skratka dne Sat
l dlouhý nazev dne Saturday
d Den (0 na počátku) 01 do 31
j Den pořadí 1 do 31
h 12 Hodina(0 na počátku) 01 do 12
g 12 Hodina 1 do 12
H 24 Hodina(0 na počátku) 00 do 23
G 24 Hodina 0 do 23
i Minuty (0 na počátku) 00 do 59
s Sekundy (0 na počátku) 00 do 59
w Den týdne(0 neděle) 0 do 6
z Den v roce 0 do 365
W Týden v roce 1 do 53
t Dnů v měsíci 28 do 31
a am nebo pm
A AM nebo PM
B Swatch Internet Time 000 do 999
S Ordinal Suffix st, nd, td, th
T Timezone of machine GMT
Z Timezone offset (seconds)
O Difference to GMT (hours)+0200
I Letní čas 1 nebo 0
L Přestupný rok 1 nebo 0
U Sekund v epoše od 1. January 1970.
c ISO 8601 (PHP 5)
r RFC 2822
Číslo týdne pro 1. leden může vrátit
53 pokud týden bude začínat předešlým rokem.
date("W", mktime(0, 0, 0, 12, 28, $year))
vždy dá správné číslo týdne v roce
$year.
date_default_timezone_set('Europe/London');
$datetime = date_create('2009-09-03 17:32:20');
echo date_format($datetime, DATE_ATOM);
// IF variable is not defined (or has a falsey value) THEN set it to an empty object.
// ELSE do nothing (technically speaking, variable gets assigned to itself)
var variable = variable || {} ;
function test(){
console.log(1);
}
// when called
test(); // 1
// or
var a = test;
a(); // 1
// or autocall if code executed
var test2 = function(){
console.log(2);
}
// test2 is undefined because the function test2 has no return value
// return string
function stringTest(param) {
return 'Hello ' + ' ' + param;
}
console.log(stringTest("Alice")); // Hello Alice
// return number
function numberTest(param) {
return 6 + param;
}
console.log(numberTest(5)); // 11
// or autocall if code executed
// function is like other variables
// parenthesis is for made groups or call functions.
// Immediately-Invoked Function Expression,
// or IIFE for short. It executes immediately after it’s created.
(function(){
// all your code here
var foo = function() {};
window.onload = foo;
// ...
})();
// foo is unreachable here (it’s undefined)
//////////////////////////////
// IIFE Immediately Invoked Funtion Expression
var greeting = function(name) {
return 'Hello ' + ' ' + name;
}('John');
console.log(greeting); // Hello John
console.log(typeof greeting); // string
console.log(greeting('Suzan')); // Uncaught TypeError: greeting is not a function
///////////////////////
var val = (function(){
var a = 0; // in the scope of this function
return function(x){
a += x;
return a;
};
})();
alert(val(10)); //10
alert(val(11)); //21
///////////////////////
// create the structure
var testHash = {
a : 1,
b : function(){
console.log(4);
},
c: function(param){
var num = param +5;
return num;
}
}
console.log(testHash.a); // 1
testHash.b(); // 4
testHash['b'](); // 4
testHash.c(7); // 12
/////////////////////////
// or function like class
function TestClass(n) {
this.some_property = n;
this.some_method = function() {
console.log(this.some_property);
};
}
var foo = new TestClass(3);
var bar = new TestClass(4);
foo.some_method(); // 3
bar.some_property += 2;
bar.some_method(); // 6
// console.log(some_property); // Uncaught ReferenceError: some_property is not defined
//////////////////////////
function Car(brand, year) {
return {
brand: brand,
year: year
}
}
var honda = Car("Honda", 1999);
console.log(honda.brand); // Honda
console.log(honda.year); // 1999
honda.brand = "Honda new Generation";
honda.year = 2021;
console.log(honda.brand); // Honda new Generation
console.log(honda.year); // 2021
var mazda = Car("Mazda",1987);
console.log(honda.brand); // Honda new Generation
console.log(mazda.brand); // Mazda
//////////////////////////////////////
// simplified code
var TEST_CLASS = TEST_CLASS || {};
TEST_CLASS.pokus = TEST_CLASS.pokus || (function() {
// -------------------------------------------------------------------------
// Private static variables and methods
// -------------------------------------------------------------------------
var privateStaticNumber = 5;
var privateStaticString = "My privateStaticString: ";
var privateStaticArray = [];
function privateStaticMethod(){
console.log('privateStaticMethod');
}
// CONSTRUCTOR CTOR
return function(config) {
// ----- private variables -----
var me = this,
isPaused = false;
this.privateStaticNumber = config.firstParam;
this.privateStaticString = privateStaticString + config.secondParam; // += produce: undefined I am from secondParam
this.privateStaticArray = config.thirtParam;
// ----- private methods -----
function getMode (mode, speed) {
// document.getElementById(mode).addEventListener('click', function () { snakeSpeed = speed; });
}
// ----- public variables -----
me.correct = 0;
me.wrong = 0;
// ----- public methods -----
me.setString = function(val) {
this.privateStaticString = val;
};
me.getString = function() {
return this.privateStaticString;
};
me.publicMethod = function(param){
console.log(param + ' from me.publicMethod()');
};
}; // end CTOR
})();
// end TEST_CLASS.pokus
var _me = _me || {};
var _me_test = new TEST_CLASS.pokus({firstParam:8, secondParam:" I am from secondParam", thirtParam:[1,3,9]});
// TEST_CLASS.pokus.privateStaticMethod(); // is not a function
// TEST_CLASS.pokus.publicMethod("Hola!"); // TEST_CLASS.pokus.publicMethod is not a function
// TEST_CLASS.publicMethod("Hola hej!"); // TEST_CLASS.publicMethod is not a function
// TEST_CLASS.pokus.publicMethod(" Hello!"); // is not a function
_me_test.publicMethod(" Hello!"); // Hello! from me.publicMethod()
console.log( _me_test.getString()); // My privateStaticString: I am from secondParam
console.log( _me_test.isPaused); // undefined
Date: 04.11.2020 - 23:14Eclipse IDE Prevent debuger to break at first line of file
Project > Properties > PHP > Debug", unselect "Break at First Line"
or
Windows -> Preferences -> PHP -> Debug" and uncheck "Break at first line".
or
Run > Debug Configurations > PHP Web Application" and unselect "Break at first line" in all the configurations.
Restart Eclipse
Date: 09.06.2020 - 20:23Letní čas tak připočítat hodinu.
Ověření zda je letní čas.
$dst = date("I"); //I (capital i); 0 or 1 if daylight saving time
// example:
$hour = 14;
if(date("I")===1){
$hour = $hour + 1;
}
// OR
$hour = 14 + date("I");
Editace: 1554584730
Počet článků v kategorii: 77
Url:regulerni-vyrazy-regex-napady-a-sablony-id-2312