simple html filter
This commit is contained in:
parent
25cf5b6078
commit
7641b372ef
387
string.php
387
string.php
@ -1,129 +1,260 @@
|
||||
<?php
|
||||
function umlaute($str) {
|
||||
return str_replace ( array (
|
||||
'Ä',
|
||||
'Ö',
|
||||
'Ü',
|
||||
'ä',
|
||||
'ö',
|
||||
'ü',
|
||||
'ß'
|
||||
), array (
|
||||
'Ä',
|
||||
'Ö',
|
||||
'Ü',
|
||||
'ä',
|
||||
'ö',
|
||||
'ü',
|
||||
'ß'
|
||||
), $str );
|
||||
}
|
||||
function chk($str) {
|
||||
return str_replace ( "'", '"', $str );
|
||||
}
|
||||
function noScript($str) {
|
||||
return str_replace ( array (
|
||||
'<',
|
||||
'>'
|
||||
), array (
|
||||
'<',
|
||||
'>'
|
||||
), $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;
|
||||
}
|
||||
|
||||
<?php
|
||||
function umlaute($str) {
|
||||
return str_replace ( array (
|
||||
'Ä',
|
||||
'Ö',
|
||||
'Ü',
|
||||
'ä',
|
||||
'ö',
|
||||
'ü',
|
||||
'ß'
|
||||
), array (
|
||||
'Ä',
|
||||
'Ö',
|
||||
'Ü',
|
||||
'ä',
|
||||
'ö',
|
||||
'ü',
|
||||
'ß'
|
||||
), $str );
|
||||
}
|
||||
function chk($str) {
|
||||
return str_replace ( "'", '"', $str );
|
||||
}
|
||||
function noScript($str) {
|
||||
return str_replace ( array (
|
||||
'<',
|
||||
'>'
|
||||
), array (
|
||||
'<',
|
||||
'>'
|
||||
), $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 (
|
||||
'{{|-<-|}}',
|
||||
'{{|->-|}}'
|
||||
), $s );
|
||||
$s = str_replace ( array (
|
||||
'{{|-<-|}}b{{|->-|}}',
|
||||
'{{|-<-|}}b/{{|->-|}}'
|
||||
), array (
|
||||
'<b>',
|
||||
'<b/>'
|
||||
), $s );
|
||||
$s = str_replace ( array (
|
||||
'{{|-<-|}}u{{|->-|}}',
|
||||
'{{|-<-|}}u/{{|->-|}}'
|
||||
), array (
|
||||
'<u>',
|
||||
'<u/>'
|
||||
), $s );
|
||||
$s = str_replace ( array (
|
||||
'{{|-<-|}}i{{|->-|}}',
|
||||
'{{|-<-|}}i/{{|->-|}}'
|
||||
), array (
|
||||
'<i>',
|
||||
'<i/>'
|
||||
), $s );
|
||||
$s = str_replace ( array (
|
||||
'{{|-<-|}}span{{|->-|}}',
|
||||
'{{|-<-|}}span/{{|->-|}}'
|
||||
), array (
|
||||
'<span>',
|
||||
'<span/>'
|
||||
), $s );
|
||||
$s = str_replace ( array (
|
||||
'{{|-<-|}}b{{|->-|}}',
|
||||
'{{|-<-|}}b/{{|->-|}}'
|
||||
), array (
|
||||
'<b>',
|
||||
'<b/>'
|
||||
), $s );
|
||||
$s = str_replace ( array (
|
||||
'{{|-<-|}}br{{|->-|}}',
|
||||
'{{|-<-|}}br/{{|->-|}}'
|
||||
), array (
|
||||
'<br>',
|
||||
'<br/>'
|
||||
), $s );
|
||||
$s = str_replace ( array (
|
||||
'{{|-<-|}}h1{{|->-|}}',
|
||||
'{{|-<-|}}h1/{{|->-|}}'
|
||||
), array (
|
||||
'<h1>',
|
||||
'<h1/>'
|
||||
), $s );
|
||||
$s = str_replace ( array (
|
||||
'{{|-<-|}}h2{{|->-|}}',
|
||||
'{{|-<-|}}h2/{{|->-|}}'
|
||||
), array (
|
||||
'<h2>',
|
||||
'<h2/>'
|
||||
), $s );
|
||||
$s = str_replace ( array (
|
||||
'{{|-<-|}}h3{{|->-|}}',
|
||||
'{{|-<-|}}h3/{{|->-|}}'
|
||||
), array (
|
||||
'<h3>',
|
||||
'<h3/>'
|
||||
), $s );
|
||||
$s = str_replace ( array (
|
||||
'{{|-<-|}}h4{{|->-|}}',
|
||||
'{{|-<-|}}h4/{{|->-|}}'
|
||||
), array (
|
||||
'<h4>',
|
||||
'<h4/>'
|
||||
), $s );
|
||||
$s = str_replace ( array (
|
||||
'{{|-<-|}}h5{{|->-|}}',
|
||||
'{{|-<-|}}h5/{{|->-|}}'
|
||||
), array (
|
||||
'<h5>',
|
||||
'<h5/>'
|
||||
), $s );
|
||||
$s = str_replace ( array (
|
||||
'{{|-<-|}}h6{{|->-|}}',
|
||||
'{{|-<-|}}h6/{{|->-|}}'
|
||||
), array (
|
||||
'<h6>',
|
||||
'<h6/>'
|
||||
), $s );
|
||||
$s = str_replace ( array (
|
||||
'{{|-<-|}}li{{|->-|}}',
|
||||
'{{|-<-|}}li/{{|->-|}}'
|
||||
), array (
|
||||
'<li>',
|
||||
'<li/>'
|
||||
), $s );
|
||||
$s = str_replace ( array (
|
||||
'{{|-<-|}}ul{{|->-|}}',
|
||||
'{{|-<-|}}ul/{{|->-|}}'
|
||||
), array (
|
||||
'<ul>',
|
||||
'<ul/>'
|
||||
), $s );
|
||||
$s = str_replace ( array (
|
||||
'{{|-<-|}}ol{{|->-|}}',
|
||||
'{{|-<-|}}ol/{{|->-|}}'
|
||||
), array (
|
||||
'<ol>',
|
||||
'<ol/>'
|
||||
), $s );
|
||||
$s = str_replace ( array (
|
||||
'{{|-<-|}}pre{{|->-|}}',
|
||||
'{{|-<-|}}pre/{{|->-|}}'
|
||||
), array (
|
||||
'<pre>',
|
||||
'<pre/>'
|
||||
), $s );
|
||||
|
||||
// cleanup
|
||||
$s = str_replace ( array (
|
||||
'{{|-',
|
||||
'-|}}'
|
||||
), array (
|
||||
'',
|
||||
''
|
||||
), $s );
|
||||
|
||||
return $s;
|
||||
}
|
||||
?>
|
||||
Loading…
Reference in New Issue
Block a user