PHP startsWith endsWith functions
PHP function get first and latest character from string
// for earlier version PHP can use mb_strlen, mb_substr if use
// diacritical accent $str = 'ěščřžýáíé';
function startsWith($haystack, $needle)
{
$length = strlen($needle);
return (substr($haystack, 0, $length) === $needle);
}
function endsWith($haystack, $needle)
{
$length = strlen($needle);
if ($length == 0) {
return true;
}
return (substr($haystack, -$length) === $needle);
}
Date: 11.06.2020 - 20:1077LW NO topic_id
AD
Další témata ....(Topics)
Pokud chceme při kompilaci kódu zobrazit chybová hlášení,
odkomentujeme příslušné řádky v souboru php.ini, jehož adresu
získáme pomocí funkce phpinfo() a přepneme Off na On u
display_errors.
Podrobnosti se dočtete v komentářích k jednotlivým nastavením v php.ini
Podrobnosti se dočtete v komentářích k jednotlivým nastavením v php.ini
error_reporting = E_ALL & ~E_NOTICE // vypise i parse errors
display_errors = On
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
Pokud často pracujete v PHP se soubory, tak se Vám může hodit
tato funkce, která vrací obsah souboru, jako string, narozdíl od funkce
file(), která vrací obsah souboru, jako pole řádků.
tato funkce, která vrací obsah souboru, jako string, narozdíl od funkce
file(), která vrací obsah souboru, jako pole řádků.
/**
* function return file content as string
* $filename is path to file
*/
function getContents($filename) {
if (function_exists('file_get_contents')) {
return file_get_contents($filename);
} else {
$fp = fopen($filename, 'r');
if (!$fp) {
echo ('Could not read contents <br/>');
return false;
}
return fread($fp, filesize($filename)); // return string
}
}
/**
* function file return file content as an array of rows
*/
$rows = file($filename);
/**
* fopen() modes
*/
r Read
r+ Read and write, prepend
w Write, truncate
w+ Read and write, truncate
a Write, append
a+ Read and write, append
Jak vybrat kód mezi taky v Notepad++
How to select f.e. javascript tag contetn in Notepad++
- insert content between braces
- put caret behind the last bracket
- press Ctrl + left Alt + B or Ctrl + Shift + B to control the first brace
from parentheses to braces and check the multi-line box.
Then you can Ctrl-double-click on either brace to highlight everything in between.
How to select f.e. javascript tag contetn in Notepad++
- insert content between braces
- put caret behind the last bracket
- press Ctrl + left Alt + B or Ctrl + Shift + B to control the first brace
< script>
{
var bla = 0;
// bla bla ... long content
} // place caret/cursor behind the last brace { and press Ctrl + left Alt + B (Notepad++)
< /script>
At Settings->Preferences->Delimiter, change the delimiters
from parentheses to braces and check the multi-line box.
Then you can Ctrl-double-click on either brace to highlight everything in between.
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:23Editace: 11.6.2020 - 20:19
Počet článků v kategorii: 77
Url:php-startswith-endswith-functions