PHP pathinfo
Nejdůležitější informace, které získáme z cesty souboru.
// soubor, který je volán jako první
print $_SERVER ['SCRIPT_FILENAME']; // /www/domain/subdomain/cesky-jazyk/gramatika/index.php
$path_parts = pathinfo($_SERVER ['SCRIPT_FILENAME']);
echo $path_parts['dirname']. " dir"; // /www/domain/subdomain/cesky-jazyk/gramatika
echo $path_parts['basename']. " base"; // index.php
echo $path_parts['extension']. " ext"; // php
echo $path_parts['filename']. " file"; // index az od PHP 5.2.0
// cesta k souboru, ve kterém je aktualni print a byl inkludován - include v index.php
print __FILE__; // /www/subdomains/cesk-jazyk/templates/header.php
77LW NO topic_id
AD
Další témata ....(Topics)
Eclipse 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:23Funkce JavaScript pro práci s datumem a časem.
function msToTime(duration) {
var milliseconds = parseInt((duration % 1000) / 100),
seconds = Math.floor((duration / 1000) % 60),
minutes = Math.floor((duration / (1000 * 60)) % 60),
hours = Math.floor((duration / (1000 * 60 * 60)) % 24);
hours = (hours < 10) ? "0" + hours : hours;
minutes = (minutes < 10) ? "0" + minutes : minutes;
seconds = (seconds < 10) ? "0" + seconds : seconds;
return hours + ":" + minutes + ":" + seconds + "." + milliseconds;
}
// console.log(msToTime(300000))
// output: 00:05:00.0
// get time difference between two dates in seconds
var startDate = new Date();
// Do your operations
var endDate = new Date();
var seconds = (endDate.getTime() - startDate.getTime()) / 1000;
var milliseconds = (endDate.getTime() - startDate.getTime());
[, OPTIONAL second param [, OPTIONAL ... param]]
static Date.now() // returns the number of milliseconds elapsed since January 1, 1970 00:00:00 UTC.
parse(dateVal) // Date.parse('05 Dec 1998 00:12:00 GMT'); // return 912816720000
toDateString() // sunday 19.7.2020
toTimeString() // 20:15:37
getDate() // 1-31
getDay() // 0-6, 0 == Sunday
var now = new Date();
var dayOfWeekSundayIs7 = now.getDay() == 0)?7:now.getDay();
getFullYear() // 2020
getHours() // 0-23
getMilliseconds() // eg. 956
getMinutes() // 0-59
getMonth() // 0 january
getSeconds() // 0-59
getTime() // https://en.wikipedia.org/wiki/Unix_time
getTimezoneOffset() //returns the time zone difference, in minutes, from current locale
getYear() //does not return full years ("year 2000 problem"), it is no longer used and has been replaced by the getFullYear() method.
setDate(numDate) // 1-31 day of month
setHours(numHours[, numMin[, numSec[, numMilli]]]) // now.setHours(20, 21, 22); 20:21:22
setMilliseconds(numMilli) // 0-999
setMinutes(numMinutes[, numSeconds[, numMilli]]) // 0-59, 0-59, 0-999
setMonth(numMonth[, dateVal]) // 0-11
setSeconds(numSeconds[, numMilli]) 0-59 [, 0-999]
setYear(numYear) // not set full years ("year 2000 problem"), it is no longer used and has been replaced by the setFullYear() method.
setUTCDate() //
setUTCFullYear(2020) // 2020 sets the full year for a specified date according to universal time GMT
setUTCHours()
setUTCMilliseconds()
setUTCMinutes()
setUTCMonth()
setUTCSeconds()
toLocaleTimeString()
var options = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' };
now.toLocaleDateString(undefined, options); //neděle 19. července 2020
// PDT Pacific Daylight Time (UTC -7)
// GMT ... SET GMT TIME +- ZONE ... new Date('December 31, 1974 23:59:30 GMT-3:00');
toGMTString() // DEPRECATED!!!! use toUTCString()
// Using UTC instead GMT!!!
var d = new Date("2020-07-15T00:00:00.000+07:00"); // UTC + 7
console.log(d.toISOString()); // "2020-07-14T17:00:00.000Z"
console.log(d.valueOf()); // 1594746000000
toISOString() // "2020-07-14T17:00:00.000Z"
toJSON() // "2020-07-14T17:00:00.000Z"
toSource() //This feature is obsolete!!!! Dont use!!!!
toString() // "Tue Jul 14 2020 19:00:00 GMT+0200 (Středoevropský letní čas)"
toUTCString() // "Tue, 14 Jul 2020 17:00:00 GMT"
valueOf() // 1594746000000
For all browsers e.g. old IE 11 ....
<script>
var mbThreadOneRunning = false;
var mbThreadOneEnded = false;
var mbThreadTwoRunning = false;
var mbThreadTwoEnded = false;
// you can create more than one Thread
// setTimeout() used for running more Threads at once
var timeout_1 = setTimeout("ThreadOne()", 5000); // 5000 == 5 second
var timeout_2 = setTimeout("ThreadTwo()", 3000); //
function ThreadOne() {
mbThreadOneRunning = true;
alert("1. ThreadOne working!");
// working code here .............
mbThreadOneEnded = true;
clearTimeout(timeout_1);
}
function ThreadTwo() {
mbThreadTwoRunning = true;
alert("2. ThreadTwo working!");
// working code here .............
mbThreadTwoEnded = true;
clearTimeout(timeout_2);
}
var mInterval = setInterval("checkThread()", 1000); // 1000 ms == 1 second, you can put smaller value
function checkThread() {
if (mbThreadOneEnded == true) {
alert("1. checkThread() ThreadOne finish work! " + mbThreadOneEnded);
}
else if (mbThreadTwoEnded == true) {
alert("2. checkThread() ThreadTwo finish work! " + mbThreadTwoEnded);
}
if (mbThreadOneEnded && mbThreadTwoEnded) {
clearInterval(mInterval); // just to be sure
mbThreadOneEnded = false;
mbThreadTwoEnded = false;
alert("ThreadOne and ThreadTwo ended ");
}
}
</script>
Ukázky zaokrouhlení čísla v JavaScript.
var num = 123.45678;
var rounded = Math.round(num); // out: 123
var num = 123.5269;
var rounded = Math.round(num); // out: 124
var num = -3.5269;
var rounded = Math.round(num); // out: -4
var num = 3.5269;
var rounded = Math.round(num * 100)/100; // out: 3.52
var num = 3.5269;
var rounded = Math.round(num * 1000)/1000; // out: 3.526
var num = 3.5269;
var rounded = num.toFixed(3); // out: 3.527
c:xampphtdocs
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
Editace: 15.5.2020 - 21:20
Počet článků v kategorii: 77
Url:php-pathinfo