javascript Sort array
How to sort array in javascript.
sort diacritical diakritika
function sortCZ(a, b) {
var token = {'á': 'a', 'č': 'c', 'ď': 'd', 'é': 'e', 'ě': 'e', 'í': 'i', 'ň': 'n', 'ř': 'r', 'š': 's', 'ť': 't', 'ú': 'u', 'ů': 'u', 'ý': 'y', 'ž': 'z'};
var code_a = (token[a]) ? token[a].charCodeAt(0) + 0.5 : a.charCodeAt(0);
var code_b = (token[b]) ? token[b].charCodeAt(0) + 0.5 : b.charCodeAt(0);
// example s=115 š will 115.5 in array immediately after s OK :)
if(token[a]){
some = token[a].charCodeAt(0) + 0.5; // 115.5
some = token[a].charCodeAt(0); // 115
}
return code_a - code_b;
}
var ar = new Array("x","č","a","c","h","z","a","ř","e","ž","ě","ň","í","d","š");
ar.sort(sortCZ);
77LW NO topic_id
AD
Další témata ....(Topics)
Textarea selection - získání pozice karety kurzoru.
// FOR Gecko Browser selectionStart / selectionEnd selection length
function getPos(){
if (typeof document.getElementById('idTextarea').selectionStart != 'undefined') {
var nPosCursor = document.getElementById('idTextarea').selectionStart;
var nEndPos = document.getElementById('idTextarea').selectionEnd;
return nPosCursor;
}
return 0; // or -1
}
// source by javascript-array.com/guides/javascript_faq/
//Internet Explorer 4+, Mozilla/Gecko/Firefox
function getCaretPos(obj)
{
obj.focus();
if(obj.selectionStart) return obj.selectionStart; //Gecko
else if (document.selection) //Internet Explorer
{
var sel = document.selection.createRange();
var clone = sel.duplicate();
sel.collapse(true);
clone.moveToElementText(obj);
clone.setEndPoint('EndToEnd', sel);
return clone.text.length;
}
return 0;
}
Example code
header("HTTP/1.1 301 Moved Permanently");
header("Location: https://www.newsite.com/new-page.php");
header("Connection: close");
exit();
If using file name without .php as part of smoothly url - example:
$fileName = basename(__FILE__, '.php');
header("HTTP/1.1 301 Moved Permanently");
header("Location: https://www.mysite.cz/auto-moto/".$fileName."/");
header("Connection: close");
exit();
Date: 23.07.2020 - 12:31Všechny příspěvky publikované na webu dum-zharada.okhelp.cz jsou zásadně jen a pouze subjektivním názorem autorů příspěvků na danou skutečnost či problematiku. Tento subjektivní názor či fikce nemusí nezbytně nutně odpovídat objektivní zkutečnosti.
Nikdo Vás nenutí řídit se informacemi získanými z příspěvků, používejte svůj vlastní rozum a logický úsudek.
Provozovatel neodpovídá za obsah komentářů. Komentáře jsou publikovány ihned po jejich zadání do systému, provozovatel je nijak neschvaluje ani neautorizuje a nemůže ovlivnit jejich obsah. Vyhrazujeme si nicméně právo libovolný komentář ex-post smazat.
Nikdo Vás nenutí řídit se informacemi získanými z příspěvků, používejte svůj vlastní rozum a logický úsudek.
Provozovatel neodpovídá za obsah komentářů. Komentáře jsou publikovány ihned po jejich zadání do systému, provozovatel je nijak neschvaluje ani neautorizuje a nemůže ovlivnit jejich obsah. Vyhrazujeme si nicméně právo libovolný komentář ex-post smazat.
Timer in javascript example source code will opening random link in random time.
// setTimeout()
// clearTimeout()
var start = new Date();
function timedCount()
{
var now = new Date();
var resultMilliSeconds = now.getTime() - start.getTime();
// create some div with id txt
document.getElementById('txt').innerHTML = resultMilliSeconds;
}
var t = setTimeout("timedCount()",1000);
// clearTimeout(t); // for stopping create button with onclick clearTimeout(t)
Použití timeru v javasciptu. Příklad otvírá náhodně náhodný odkaz v okně prohlížeče za náhodný časový interval.
var c=0;
var t = new String().toString();
var t2 = new String().toString();
var timer_is_on=0;
var newWindow;
function open2(url, opt){
if (opt == 0) // current window
window.location = url;
else if (opt == 1){ // new window
if(newWindow) newWindow.open(url,"_parent");
else
newWindow = window.open(url);
}
else if (opt == 2) // background window
{window.open(url); self.focus();}
}
var ar = new Array (
"https://www.okhelp.cz/polevky/"
,"https://www.okhelp.cz/auto-moto/"
,"https://www.okhelp.cz/pc-mobily/"
);
function timedCount()
{
var randomnumber=Math.floor(Math.random()*ar.length)
open2(ar[randomnumber],1);
document.getElementById('txt').value=c;
c=c+1;
t=setTimeout("timedCount()",1000 * (randomnumber + 4));
}
function doTimer()
{
if (!timer_is_on)
{
timer_is_on=1;
timedCount();
}
}
function stopCount()
{
clearTimeout(t);
clearTimeout(t2);
timer_is_on=0;
}
</script>
</head>
<body>
<form>
<input type="button" value="Start count!" onClick="doTimer()">
<input type="text" id="txt">
<input type="button" value="Stop count!" onClick="stopCount()">
</form>
Jak získat obsah určité složky příklad v php.
/*************************
* vyhleda soubory s prislusnou koncovkou
* a vrátí nejmladsi soubor
* $extension
*/
function getFileFromDir($path, $extension)
{ // BEGIN function getFileFromDir
$fileReturn; $z = 0;
if (is_dir ($path)) {
$dh = opendir($path); // or die (" Directory Open failed !");
while ($file = readdir($dh)){
//print $file.'<br />';
if (is_file($path.$file)) {
//print $file.'<br />';
$ar = explode(".", $file);
if (count($ar) > 1) {
if (strtolower($ar[count($ar) - 1]) == $extension) { // "zip", "exe" or other extension
$fileReturn[$z][0] = date ("Ymd", filemtime($path.$file));
$fileReturn[$z][1] = $file;
$z++;
//break;
}
}
}
}
closedir ($dh);
}
if ($fileReturn) {
sort($fileReturn);
return $fileReturn[count($fileReturn) - 1][1];
}
} // END function getFileFromDir
/***************************
Editace: 18 10 2016
Počet článků v kategorii: 77
Url:javascript-sort-array