2 Commits

Author SHA1 Message Date
admin
df5d1447af Merge branch 'master' of https://git.seemsleg.it/pub/php-func-lib
Conflicts:
	string.php
2021-07-13 21:38:08 +02:00
admin
2352fd5396 linkify tool um urls in text in echte links zu verwandeln 2021-07-13 21:37:14 +02:00

View File

@@ -1,260 +1,526 @@
<?php <<<<<<< HEAD
function umlaute($str) { <?php
return str_replace ( array ( function umlaute($str) {
'Ä', return str_replace ( array (
'Ö', 'Ä',
'Ü', 'Ö',
'ä', 'Ü',
'ö', 'ä',
'ü', 'ö',
'ß' 'ü',
), array ( 'ß'
'&Auml;', ), array (
'&Ouml;', '&Auml;',
'&Uuml;', '&Ouml;',
'&auml;', '&Uuml;',
'&ouml;', '&auml;',
'&uuml;', '&ouml;',
'&szlig;' '&uuml;',
), $str ); '&szlig;'
} ), $str );
function chk($str) { }
return str_replace ( "'", '"', $str ); function chk($str) {
} return str_replace ( "'", '"', $str );
function noScript($str) { }
return str_replace ( array ( function noScript($str) {
'<', return str_replace ( array (
'>' '<',
), array ( '>'
'&lt;', ), array (
'&gt;' '&lt;',
), $str ); '&gt;'
} ), $str );
function random($name_laenge) { }
$zeichen = "abcedfghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRTSUVWXYZ0123456789"; function random($name_laenge) {
$name_neu = ""; $zeichen = "abcedfghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRTSUVWXYZ0123456789";
$name_neu = "";
@mt_srand ( ( double ) microtime () * 1000000 );
for($i = 0; $i < $name_laenge; $i ++) { @mt_srand ( ( double ) microtime () * 1000000 );
$r = mt_rand ( 0, strlen ( $zeichen ) - 1 ); for($i = 0; $i < $name_laenge; $i ++) {
$name_neu .= $zeichen {$r}; $r = mt_rand ( 0, strlen ( $zeichen ) - 1 );
} $name_neu .= $zeichen {$r};
return $name_neu; }
} return $name_neu;
function startsWith($haystack, $needle) { }
$length = strlen ( $needle ); function startsWith($haystack, $needle) {
return (substr ( $haystack, 0, $length ) === $needle); $length = strlen ( $needle );
} return (substr ( $haystack, 0, $length ) === $needle);
function endsWith($haystack, $needle) { }
$length = strlen ( $needle ); function endsWith($haystack, $needle) {
$length = strlen ( $needle );
return $length === 0 || (substr ( $haystack, - $length ) === $needle);
} return $length === 0 || (substr ( $haystack, - $length ) === $needle);
function onlyAlpha($str, $zus = '') { }
return preg_replace ( "/[^a-zA-Z0-9 \-\_{$zus}]+/", "", $str ); function onlyAlpha($str, $zus = '') {
} return preg_replace ( "/[^a-zA-Z0-9 \-\{$zus}_]+/", "", $str );
function shortener($str, $len = 50, $fill = '...') { }
if (strlen ( $str ) > $len) { function shortener($str, $len = 50, $fill = '...') {
$str = substr ( $str, 0, $len - strlen ( $fill ) ) . $fill; if (strlen ( $str ) > $len) {
} $str = substr ( $str, 0, $len - strlen ( $fill ) ) . $fill;
return $str; }
} return $str;
function isEmail($str) { }
$match = preg_match ( "/[a-zA-Z0-9\-\_\.]*\@[a-zA-Z0-9\-\_\.]*.[a-z]{2,10}/", $str ); function isEmail($str) {
if ($match) { $match = preg_match ( "/[a-zA-Z0-9\-\_\.]*\@[a-zA-Z0-9\-\_\.]*.[a-z]{2,10}/", $str );
return $str; if ($match) {
} return $str;
return false; }
} return false;
function markUp($text) { }
$r = ''; function markUp($text) {
$lv = 0; $r = '';
foreach ( explode ( "\n", $text ) as $t ) { $lv = 0;
$nlv = 0; foreach ( explode ( "\n", $text ) as $t ) {
if (startsWith ( '**** ', $t )) { $nlv = 0;
$t = substr ( $t, 5 ); if (startsWith ( '**** ', $t )) {
$nlv = 4; $t = substr ( $t, 5 );
} $nlv = 4;
if (startsWith ( '*** ', $t )) { }
$t = substr ( $t, 4 ); if (startsWith ( '*** ', $t )) {
$nlv = 3; $t = substr ( $t, 4 );
} $nlv = 3;
if (startsWith ( '** ', $t )) { }
$t = substr ( $t, 3 ); if (startsWith ( '** ', $t )) {
$nlv = 2; $t = substr ( $t, 3 );
} $nlv = 2;
if (startsWith ( '* ', $t )) { }
$t = substr ( $t, 2 ); if (startsWith ( '* ', $t )) {
$nlv = 1; $t = substr ( $t, 2 );
} $nlv = 1;
if ($lv != $nlv) { }
while ( $lv < $nlv ) { if ($lv != $nlv) {
$text .= '<ul>'; while ( $lv < $nlv ) {
$lv ++; $text .= '<ul>';
} $lv ++;
while ( $lv > $nlv ) { }
$text .= '</ul>'; while ( $lv > $nlv ) {
$lv --; $text .= '</ul>';
} $lv --;
} }
if (startsWith ( $t, '!!!!! ' )) { }
$t = '<h5>' . substr ( $t, 6 ) . '</h5>'; if (startsWith ( $t, '!!!!! ' )) {
} $t = '<h5>' . substr ( $t, 6 ) . '</h5>';
if (startsWith ( $t, '!!!! ' )) { }
$t = '<h4>' . substr ( $t, 5 ) . '</h4>'; if (startsWith ( $t, '!!!! ' )) {
} $t = '<h4>' . substr ( $t, 5 ) . '</h4>';
if (startsWith ( $t, '!!! ' )) { }
$t = '<h3>' . substr ( $t, 4 ) . '</h3>'; if (startsWith ( $t, '!!! ' )) {
} $t = '<h3>' . substr ( $t, 4 ) . '</h3>';
if (startsWith ( $t, '!! ' )) { }
$t = '<h2>' . substr ( $t, 3 ) . '</h2>'; if (startsWith ( $t, '!! ' )) {
} $t = '<h2>' . substr ( $t, 3 ) . '</h2>';
if (startsWith ( $t, '! ' )) { }
$t = '<h1>' . substr ( $t, 2 ) . '</h1>'; if (startsWith ( $t, '! ' )) {
} $t = '<h1>' . substr ( $t, 2 ) . '</h1>';
if ($lv == 0) { }
$r .= $t; if ($lv == 0) {
} else { $r .= $t;
$r .= '<li>' . $t . '</li>'; } else {
} $r .= '<li>' . $t . '</li>';
// var_dump ( $t ); }
} // var_dump ( $t );
while ( $lv > 0 ) { }
$r .= '</ul>'; while ( $lv > 0 ) {
$lv --; $r .= '</ul>';
} $lv --;
return $r; }
} return $r;
function onlySimpleHTML($s) { }
$s = str_replace ( array ( function onlySimpleHTML($s) {
'<', $s = str_replace ( array (
'>' '<',
), array ( '>'
'{{|-&lt;-|}}', ), array (
'{{|-&gt;-|}}' '{{|-&lt;-|}}',
), $s ); '{{|-&gt;-|}}'
$s = str_replace ( array ( ), $s );
'{{|-&lt;-|}}b{{|-&gt;-|}}', $s = str_replace ( array (
'{{|-&lt;-|}}b/{{|-&gt;-|}}' '{{|-&lt;-|}}b{{|-&gt;-|}}',
), array ( '{{|-&lt;-|}}b/{{|-&gt;-|}}'
'<b>', ), array (
'<b/>' '<b>',
), $s ); '<b/>'
$s = str_replace ( array ( ), $s );
'{{|-&lt;-|}}u{{|-&gt;-|}}', $s = str_replace ( array (
'{{|-&lt;-|}}u/{{|-&gt;-|}}' '{{|-&lt;-|}}u{{|-&gt;-|}}',
), array ( '{{|-&lt;-|}}u/{{|-&gt;-|}}'
'<u>', ), array (
'<u/>' '<u>',
), $s ); '<u/>'
$s = str_replace ( array ( ), $s );
'{{|-&lt;-|}}i{{|-&gt;-|}}', $s = str_replace ( array (
'{{|-&lt;-|}}i/{{|-&gt;-|}}' '{{|-&lt;-|}}i{{|-&gt;-|}}',
), array ( '{{|-&lt;-|}}i/{{|-&gt;-|}}'
'<i>', ), array (
'<i/>' '<i>',
), $s ); '<i/>'
$s = str_replace ( array ( ), $s );
'{{|-&lt;-|}}span{{|-&gt;-|}}', $s = str_replace ( array (
'{{|-&lt;-|}}span/{{|-&gt;-|}}' '{{|-&lt;-|}}span{{|-&gt;-|}}',
), array ( '{{|-&lt;-|}}span/{{|-&gt;-|}}'
'<span>', ), array (
'<span/>' '<span>',
), $s ); '<span/>'
$s = str_replace ( array ( ), $s );
'{{|-&lt;-|}}b{{|-&gt;-|}}', $s = str_replace ( array (
'{{|-&lt;-|}}b/{{|-&gt;-|}}' '{{|-&lt;-|}}b{{|-&gt;-|}}',
), array ( '{{|-&lt;-|}}b/{{|-&gt;-|}}'
'<b>', ), array (
'<b/>' '<b>',
), $s ); '<b/>'
$s = str_replace ( array ( ), $s );
'{{|-&lt;-|}}br{{|-&gt;-|}}', $s = str_replace ( array (
'{{|-&lt;-|}}br/{{|-&gt;-|}}' '{{|-&lt;-|}}br{{|-&gt;-|}}',
), array ( '{{|-&lt;-|}}br/{{|-&gt;-|}}'
'<br>', ), array (
'<br/>' '<br>',
), $s ); '<br/>'
$s = str_replace ( array ( ), $s );
'{{|-&lt;-|}}h1{{|-&gt;-|}}', $s = str_replace ( array (
'{{|-&lt;-|}}h1/{{|-&gt;-|}}' '{{|-&lt;-|}}h1{{|-&gt;-|}}',
), array ( '{{|-&lt;-|}}h1/{{|-&gt;-|}}'
'<h1>', ), array (
'<h1/>' '<h1>',
), $s ); '<h1/>'
$s = str_replace ( array ( ), $s );
'{{|-&lt;-|}}h2{{|-&gt;-|}}', $s = str_replace ( array (
'{{|-&lt;-|}}h2/{{|-&gt;-|}}' '{{|-&lt;-|}}h2{{|-&gt;-|}}',
), array ( '{{|-&lt;-|}}h2/{{|-&gt;-|}}'
'<h2>', ), array (
'<h2/>' '<h2>',
), $s ); '<h2/>'
$s = str_replace ( array ( ), $s );
'{{|-&lt;-|}}h3{{|-&gt;-|}}', $s = str_replace ( array (
'{{|-&lt;-|}}h3/{{|-&gt;-|}}' '{{|-&lt;-|}}h3{{|-&gt;-|}}',
), array ( '{{|-&lt;-|}}h3/{{|-&gt;-|}}'
'<h3>', ), array (
'<h3/>' '<h3>',
), $s ); '<h3/>'
$s = str_replace ( array ( ), $s );
'{{|-&lt;-|}}h4{{|-&gt;-|}}', $s = str_replace ( array (
'{{|-&lt;-|}}h4/{{|-&gt;-|}}' '{{|-&lt;-|}}h4{{|-&gt;-|}}',
), array ( '{{|-&lt;-|}}h4/{{|-&gt;-|}}'
'<h4>', ), array (
'<h4/>' '<h4>',
), $s ); '<h4/>'
$s = str_replace ( array ( ), $s );
'{{|-&lt;-|}}h5{{|-&gt;-|}}', $s = str_replace ( array (
'{{|-&lt;-|}}h5/{{|-&gt;-|}}' '{{|-&lt;-|}}h5{{|-&gt;-|}}',
), array ( '{{|-&lt;-|}}h5/{{|-&gt;-|}}'
'<h5>', ), array (
'<h5/>' '<h5>',
), $s ); '<h5/>'
$s = str_replace ( array ( ), $s );
'{{|-&lt;-|}}h6{{|-&gt;-|}}', $s = str_replace ( array (
'{{|-&lt;-|}}h6/{{|-&gt;-|}}' '{{|-&lt;-|}}h6{{|-&gt;-|}}',
), array ( '{{|-&lt;-|}}h6/{{|-&gt;-|}}'
'<h6>', ), array (
'<h6/>' '<h6>',
), $s ); '<h6/>'
$s = str_replace ( array ( ), $s );
'{{|-&lt;-|}}li{{|-&gt;-|}}', $s = str_replace ( array (
'{{|-&lt;-|}}li/{{|-&gt;-|}}' '{{|-&lt;-|}}li{{|-&gt;-|}}',
), array ( '{{|-&lt;-|}}li/{{|-&gt;-|}}'
'<li>', ), array (
'<li/>' '<li>',
), $s ); '<li/>'
$s = str_replace ( array ( ), $s );
'{{|-&lt;-|}}ul{{|-&gt;-|}}', $s = str_replace ( array (
'{{|-&lt;-|}}ul/{{|-&gt;-|}}' '{{|-&lt;-|}}ul{{|-&gt;-|}}',
), array ( '{{|-&lt;-|}}ul/{{|-&gt;-|}}'
'<ul>', ), array (
'<ul/>' '<ul>',
), $s ); '<ul/>'
$s = str_replace ( array ( ), $s );
'{{|-&lt;-|}}ol{{|-&gt;-|}}', $s = str_replace ( array (
'{{|-&lt;-|}}ol/{{|-&gt;-|}}' '{{|-&lt;-|}}ol{{|-&gt;-|}}',
), array ( '{{|-&lt;-|}}ol/{{|-&gt;-|}}'
'<ol>', ), array (
'<ol/>' '<ol>',
), $s ); '<ol/>'
$s = str_replace ( array ( ), $s );
'{{|-&lt;-|}}pre{{|-&gt;-|}}', $s = str_replace ( array (
'{{|-&lt;-|}}pre/{{|-&gt;-|}}' '{{|-&lt;-|}}pre{{|-&gt;-|}}',
), array ( '{{|-&lt;-|}}pre/{{|-&gt;-|}}'
'<pre>', ), array (
'<pre/>' '<pre>',
), $s ); '<pre/>'
), $s );
// cleanup
$s = str_replace ( array ( // cleanup
'{{|-', $s = str_replace ( array (
'-|}}' '{{|-',
), array ( '-|}}'
'', ), array (
'' '',
), $s ); ''
), $s );
return $s;
} return $s;
}
function linkify($input) {
$pattern = '@(http(s)?://)?(([a-zA-Z])([-\w]+\.)+([^\s\.]+[^\s]*)+[^,.\s])@';
return $output = preg_replace ( $pattern, '<a href="http$2://$3">$0</a>', $input );
}
=======
<?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, $zus = '') {
return preg_replace ( "/[^a-zA-Z0-9 \-\_{$zus}]+/", "", $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;
}
function markUp($text) {
$r = '';
$lv = 0;
foreach ( explode ( "\n", $text ) as $t ) {
$nlv = 0;
if (startsWith ( '**** ', $t )) {
$t = substr ( $t, 5 );
$nlv = 4;
}
if (startsWith ( '*** ', $t )) {
$t = substr ( $t, 4 );
$nlv = 3;
}
if (startsWith ( '** ', $t )) {
$t = substr ( $t, 3 );
$nlv = 2;
}
if (startsWith ( '* ', $t )) {
$t = substr ( $t, 2 );
$nlv = 1;
}
if ($lv != $nlv) {
while ( $lv < $nlv ) {
$text .= '<ul>';
$lv ++;
}
while ( $lv > $nlv ) {
$text .= '</ul>';
$lv --;
}
}
if (startsWith ( $t, '!!!!! ' )) {
$t = '<h5>' . substr ( $t, 6 ) . '</h5>';
}
if (startsWith ( $t, '!!!! ' )) {
$t = '<h4>' . substr ( $t, 5 ) . '</h4>';
}
if (startsWith ( $t, '!!! ' )) {
$t = '<h3>' . substr ( $t, 4 ) . '</h3>';
}
if (startsWith ( $t, '!! ' )) {
$t = '<h2>' . substr ( $t, 3 ) . '</h2>';
}
if (startsWith ( $t, '! ' )) {
$t = '<h1>' . substr ( $t, 2 ) . '</h1>';
}
if ($lv == 0) {
$r .= $t;
} else {
$r .= '<li>' . $t . '</li>';
}
// var_dump ( $t );
}
while ( $lv > 0 ) {
$r .= '</ul>';
$lv --;
}
return $r;
}
function onlySimpleHTML($s) {
$s = str_replace ( array (
'<',
'>'
), array (
'{{|-&lt;-|}}',
'{{|-&gt;-|}}'
), $s );
$s = str_replace ( array (
'{{|-&lt;-|}}b{{|-&gt;-|}}',
'{{|-&lt;-|}}b/{{|-&gt;-|}}'
), array (
'<b>',
'<b/>'
), $s );
$s = str_replace ( array (
'{{|-&lt;-|}}u{{|-&gt;-|}}',
'{{|-&lt;-|}}u/{{|-&gt;-|}}'
), array (
'<u>',
'<u/>'
), $s );
$s = str_replace ( array (
'{{|-&lt;-|}}i{{|-&gt;-|}}',
'{{|-&lt;-|}}i/{{|-&gt;-|}}'
), array (
'<i>',
'<i/>'
), $s );
$s = str_replace ( array (
'{{|-&lt;-|}}span{{|-&gt;-|}}',
'{{|-&lt;-|}}span/{{|-&gt;-|}}'
), array (
'<span>',
'<span/>'
), $s );
$s = str_replace ( array (
'{{|-&lt;-|}}b{{|-&gt;-|}}',
'{{|-&lt;-|}}b/{{|-&gt;-|}}'
), array (
'<b>',
'<b/>'
), $s );
$s = str_replace ( array (
'{{|-&lt;-|}}br{{|-&gt;-|}}',
'{{|-&lt;-|}}br/{{|-&gt;-|}}'
), array (
'<br>',
'<br/>'
), $s );
$s = str_replace ( array (
'{{|-&lt;-|}}h1{{|-&gt;-|}}',
'{{|-&lt;-|}}h1/{{|-&gt;-|}}'
), array (
'<h1>',
'<h1/>'
), $s );
$s = str_replace ( array (
'{{|-&lt;-|}}h2{{|-&gt;-|}}',
'{{|-&lt;-|}}h2/{{|-&gt;-|}}'
), array (
'<h2>',
'<h2/>'
), $s );
$s = str_replace ( array (
'{{|-&lt;-|}}h3{{|-&gt;-|}}',
'{{|-&lt;-|}}h3/{{|-&gt;-|}}'
), array (
'<h3>',
'<h3/>'
), $s );
$s = str_replace ( array (
'{{|-&lt;-|}}h4{{|-&gt;-|}}',
'{{|-&lt;-|}}h4/{{|-&gt;-|}}'
), array (
'<h4>',
'<h4/>'
), $s );
$s = str_replace ( array (
'{{|-&lt;-|}}h5{{|-&gt;-|}}',
'{{|-&lt;-|}}h5/{{|-&gt;-|}}'
), array (
'<h5>',
'<h5/>'
), $s );
$s = str_replace ( array (
'{{|-&lt;-|}}h6{{|-&gt;-|}}',
'{{|-&lt;-|}}h6/{{|-&gt;-|}}'
), array (
'<h6>',
'<h6/>'
), $s );
$s = str_replace ( array (
'{{|-&lt;-|}}li{{|-&gt;-|}}',
'{{|-&lt;-|}}li/{{|-&gt;-|}}'
), array (
'<li>',
'<li/>'
), $s );
$s = str_replace ( array (
'{{|-&lt;-|}}ul{{|-&gt;-|}}',
'{{|-&lt;-|}}ul/{{|-&gt;-|}}'
), array (
'<ul>',
'<ul/>'
), $s );
$s = str_replace ( array (
'{{|-&lt;-|}}ol{{|-&gt;-|}}',
'{{|-&lt;-|}}ol/{{|-&gt;-|}}'
), array (
'<ol>',
'<ol/>'
), $s );
$s = str_replace ( array (
'{{|-&lt;-|}}pre{{|-&gt;-|}}',
'{{|-&lt;-|}}pre/{{|-&gt;-|}}'
), array (
'<pre>',
'<pre/>'
), $s );
// cleanup
$s = str_replace ( array (
'{{|-',
'-|}}'
), array (
'',
''
), $s );
return $s;
}
>>>>>>> branch 'master' of https://git.seemsleg.it/pub/php-func-lib
?> ?>