php-func-lib/string.php
2019-11-05 18:13:26 +01:00

70 lines
1.4 KiB
PHP

<?php
function umlaute($str) {
return str_replace(array(
'Ä',
'Ö',
'Ü',
'ä',
'ö',
'ü',
'ß'
), array(
'&Auml;',
'&Ouml;',
'&Uuml;',
'&auml;',
'&ouml;',
'&uuml;',
'&szlig;'
), $str);
}
function chk($str) {
return str_replace("'", '"', $str);
}
function noScript($str) {
return str_replace(array(
'<',
'>'
), array(
'&lt;',
'&gt;'
), $str);
}
function random($name_laenge) {
$zeichen = "abcedfghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRTSUVWXYZ0123456789";
$name_neu = "";
@mt_srand((double)microtime() * 1000000);
for($i = 0; $i < $name_laenge; $i++){
$r = mt_rand(0, strlen($zeichen) - 1);
$name_neu .= $zeichen{$r};
}
return $name_neu;
}
function startsWith($haystack, $needle) {
$length = strlen($needle);
return (substr($haystack, 0, $length) === $needle);
}
function endsWith($haystack, $needle) {
$length = strlen($needle);
return $length === 0 || (substr($haystack, -$length) === $needle);
}
function onlyAlpha($str) {
return preg_replace("/[^a-zA-Z0-9 \-\_]+/", "", $str);
}
function shortener($str, $len = 50, $fill = '...') {
if(strlen($str) > $len){
$str = substr($str, 0, $len - strlen($fill)) . $fill;
}
return $str;
}
function isEmail($str) {
$match = preg_match("/[a-zA-Z0-9\-\_\.]*\@[a-zA-Z0-9\-\_\.]*.[a-z]{2,10}/", $str);
if($match){
return $str;
}
return false;
}
?>