PHP redirect 301 example code
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:3177LW NO topic_id
AD
Další témata ....(Topics)
g | Global / najde všechny, nezastaví se po prvním nálezu |
m | Multiline / prohledá i v dalších řádcích |
i | Case insensitive / citlivý na velikost písmen |
x | Ignore whitespace / ignoruje všechny mezery a umožňuje vložení komentáře do regexu. Komentáře jsou označeny znakem "#". Pokud potřebujete zahrnout znak mezery ve vašem regexu musíte jej označit '\ ' |
s | Single line |
u | Unicode / \w+ již pak vybere celé slovo i když obsahuje například českou dikakritiku |
X | eXtended |
U | Ungreedy / např. a+ vybere jen první a z aaaaaa |
A | Anchor / např. a+ označí první výskyt a a všechny další a pokud jej následují holaaaahou už ne aaa |
J | Duplicate group names / regex může mít duplicitní názvy vzorů, ale každá skupina vyhledání má stále své vlastní ID. Npř. /(?<letter>a)(?<letter>b)/J Tyto dvě skupiny produkují vlastní zápas namísto jedné kombinované skupiny. ab bude rozděleno do dvou skupin. Full match bude ab |
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
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;
}
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:23Php 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
Editace: 23.7.2020 - 12:39
Počet článků v kategorii: 77
Url:php-redirect-301-example-code