Okhelp.cz

Recepty, články, nápady, programování. Dříve dum-zahrada, finance, internet a know-how.okhelp.cz Pro lepší výsledky hledání používejte i diakritiku.

PHP redirect 301 example code


AD MOB

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:31

77LW NO topic_id




AD

Další témata ....(Topics)


38

PHP Multi byte mode | php-multi-byte-mode


Multi-byte UNICODE PHP.

Pokud pracujete s diakritikou budou se Vám hodit funkce, které začínají mb_ tedy multi-byte funkce.
Abyste nemuseli do každé funkce udávat kódování viz příklad

$mbLen = mb_strlen('žluťoučký','utf-8');

přidávejte na začátek kódu internal encoding

mb_internal_encoding('utf-8');
$mbLen = mb_strlen('žluťoučký');

Příklad si vyzkoušejte a ověřte hodnoty $mbLen
43

javascript Date functions milliseconds to time hours minutes seconds | javascript-date-functions


Funkce 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


44

javascript Object methods | javascript-object-methods


 

toString([radix])
/* prevede objekt na string */

toLocaleString()
var myDate = new Date(); 
document.write( myDate.toLocaleString());
// 24. února 2009 10:50:02 

valueOf()
    var number = new Number();
    number = Number(100);
    if (!isNaN(number))
        document.write(number.valueOf()); // 100


hasOwnProperty(proName)
var theObj = { prom : 'bla' };
if ( theObj.hasOwnProperty )
{
  document.write( "Has 'prom': " + theObj.hasOwnProperty( 'prom' ) + 'n' ); // true
  document.write( "Has 'prom2': " + theObj.hasOwnProperty( 'prom2' ) + 'n' ); // false
}


isPrototypeOf(object2)
function fc(){
  var reg = new RegExp();                        
  return (RegExp.prototype.isPrototypeOf(reg));  // return true.
}



propertyIsEnumerable(proName)
  var a = new Array("apple", "banana", "cactus");
  document.write(a.propertyIsEnumerable(2)); // true




47

Foreach in javascript | foreach-in-javascript


Foreach fore each in javascript loop cycle example source code

Example code foreach for JavaScript.

var arr = new Array(1,2,3,4,5,6);// numbers or string put into array
for (var key in arr) {
    window.alert("My array"
                 + key
                 + " = "
                 + arr[key]);
}

// next example
arr.forEach(function(elem){
		console.log(elem);
	});

// next example
for (var i = 0; i < arr.length; i++) {
  alert (arr[i]);
}

// next example for GECKO MOZILLA FIREFOX
var soucet = 0;
var obj = {var1: 5, var2: 13, var3: 8};
for each (var item in obj) {
  soucet += item;
}
alert(soucet); // vysledek "26", coz je soucet 5+13+8




Each in jQuery get all document inputs type text and set value 0 if checkbox checked


function fc(th){
 if( th.checked ){
    $("input:text").each(
    function() {
        this.value = 0;
        this.disabled = true;
      }
    ); 

}else{
    $("input:text").each(
    function() {

        this.disabled = false;
      }
    ); 
}

<input type="checkbox"  id="idCheck"  onchange="fc(this);"> Checkbox 
 
<input type="text" size="1" id="id1"  value="0"  /> 

<input type="text" size="1" id="id2"  value="0"  /> 


42

javascript Array functions | javascript-array-functions


Některé funkce pracující s polem v JavaScriptu

concat([item1[, item2[, . . . [, itemN]]]])
concat([string2[, string3[, . . . [, stringN]]]])
/* spoji stringy nebo pole a vraci novy string nebo pole */

join(separator)
/* vrati v string spojene itemy poli oddelene separatorem*/

push([item1 [item2 [. . . [itemN ]]]])
/* prida na konec pole novy item a vraci delku pole*/

pop()
/* odebere posledni element z pole a vrati jeho hodnotu*/

reverse()
/*vraci obracene poradi itemu pole*/

shift()
/* odebere prvni item z pole a vrati jej*/

slice(start, [end])
/* varaci cast pole*/
  var  numArray = new Array(3,2,5,9);
  var  newNumArray = numArray.slice(1,3); // 2,5



sort(sortFunction)
/* setridi pole */

splice(start, deleteCount, [item1[, item2[, . . . [,itemN]]]])
/* odebere element z pole, popripade vlozi novy a vrati odebrany element*/
    var numArray = new Array(3,2,5,9);
    var newNumArray = numArray.splice(1,1); // 3,5,9


unshift([item1[, item2 [, . . . [, itemN]]]])
/* prida na pocatek item, ktery je parametrem funkce  */
var myA = new Array(10,11,12); 
myA.unshift(1); // 1,10,11,12








Editace: 23.7.2020 - 12:39
Počet článků v kategorii: 77
Url:php-redirect-301-example-code

AD
11 Share
Share
Tweet