From b2e6260dfb8976fb703540ee1f770266bb005089 Mon Sep 17 00:00:00 2001 From: Sebastian Titz Date: Thu, 15 Jul 2021 08:56:38 +0200 Subject: [PATCH] in string fkt --- string.php | 450 ++++++++++++----------------------------------------- 1 file changed, 97 insertions(+), 353 deletions(-) diff --git a/string.php b/string.php index 1008339..7b50b53 100644 --- a/string.php +++ b/string.php @@ -1,22 +1,21 @@ -<<<<<<< HEAD ' + '<', + '>' ), 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 ); @@ -48,7 +47,7 @@ function startsWith($haystack, $needle) { } function endsWith($haystack, $needle) { $length = strlen ( $needle ); - + return $length === 0 || (substr ( $haystack, - $length ) === $needle); } function onlyAlpha($str, $zus = '') { @@ -128,399 +127,144 @@ function markUp($text) { } function onlySimpleHTML($s) { $s = str_replace ( array ( - '<', - '>' + '<', + '>' ), array ( - '{{|-<-|}}', - '{{|->-|}}' + '{{|-<-|}}', + '{{|->-|}}' ), $s ); $s = str_replace ( array ( - '{{|-<-|}}b{{|->-|}}', - '{{|-<-|}}b/{{|->-|}}' + '{{|-<-|}}b{{|->-|}}', + '{{|-<-|}}b/{{|->-|}}' ), array ( - '', - '' + '', + '' ), $s ); $s = str_replace ( array ( - '{{|-<-|}}u{{|->-|}}', - '{{|-<-|}}u/{{|->-|}}' + '{{|-<-|}}u{{|->-|}}', + '{{|-<-|}}u/{{|->-|}}' ), array ( - '', - '' + '', + '' ), $s ); $s = str_replace ( array ( - '{{|-<-|}}i{{|->-|}}', - '{{|-<-|}}i/{{|->-|}}' + '{{|-<-|}}i{{|->-|}}', + '{{|-<-|}}i/{{|->-|}}' ), array ( - '', - '' + '', + '' ), $s ); $s = str_replace ( array ( - '{{|-<-|}}span{{|->-|}}', - '{{|-<-|}}span/{{|->-|}}' + '{{|-<-|}}span{{|->-|}}', + '{{|-<-|}}span/{{|->-|}}' ), array ( - '', - '' + '', + '' ), $s ); $s = str_replace ( array ( - '{{|-<-|}}b{{|->-|}}', - '{{|-<-|}}b/{{|->-|}}' + '{{|-<-|}}b{{|->-|}}', + '{{|-<-|}}b/{{|->-|}}' ), array ( - '', - '' + '', + '' ), $s ); $s = str_replace ( array ( - '{{|-<-|}}br{{|->-|}}', - '{{|-<-|}}br/{{|->-|}}' + '{{|-<-|}}br{{|->-|}}', + '{{|-<-|}}br/{{|->-|}}' ), array ( - '
', - '
' + '
', + '
' ), $s ); $s = str_replace ( array ( - '{{|-<-|}}h1{{|->-|}}', - '{{|-<-|}}h1/{{|->-|}}' + '{{|-<-|}}h1{{|->-|}}', + '{{|-<-|}}h1/{{|->-|}}' ), array ( - '

', - '

' + '

', + '

' ), $s ); $s = str_replace ( array ( - '{{|-<-|}}h2{{|->-|}}', - '{{|-<-|}}h2/{{|->-|}}' + '{{|-<-|}}h2{{|->-|}}', + '{{|-<-|}}h2/{{|->-|}}' ), array ( - '

', - '

' + '

', + '

' ), $s ); $s = str_replace ( array ( - '{{|-<-|}}h3{{|->-|}}', - '{{|-<-|}}h3/{{|->-|}}' + '{{|-<-|}}h3{{|->-|}}', + '{{|-<-|}}h3/{{|->-|}}' ), array ( - '

', - '

' + '

', + '

' ), $s ); $s = str_replace ( array ( - '{{|-<-|}}h4{{|->-|}}', - '{{|-<-|}}h4/{{|->-|}}' + '{{|-<-|}}h4{{|->-|}}', + '{{|-<-|}}h4/{{|->-|}}' ), array ( - '

', - '

' + '

', + '

' ), $s ); $s = str_replace ( array ( - '{{|-<-|}}h5{{|->-|}}', - '{{|-<-|}}h5/{{|->-|}}' + '{{|-<-|}}h5{{|->-|}}', + '{{|-<-|}}h5/{{|->-|}}' ), array ( - '

', - '
' + '
', + '
' ), $s ); $s = str_replace ( array ( - '{{|-<-|}}h6{{|->-|}}', - '{{|-<-|}}h6/{{|->-|}}' + '{{|-<-|}}h6{{|->-|}}', + '{{|-<-|}}h6/{{|->-|}}' ), array ( - '
', - '
' + '
', + '
' ), $s ); $s = str_replace ( array ( - '{{|-<-|}}li{{|->-|}}', - '{{|-<-|}}li/{{|->-|}}' + '{{|-<-|}}li{{|->-|}}', + '{{|-<-|}}li/{{|->-|}}' ), array ( - '
  • ', - '
  • ' + '
  • ', + '
  • ' ), $s ); $s = str_replace ( array ( - '{{|-<-|}}ul{{|->-|}}', - '{{|-<-|}}ul/{{|->-|}}' + '{{|-<-|}}ul{{|->-|}}', + '{{|-<-|}}ul/{{|->-|}}' ), array ( - '
      ', - '
        ' + '
          ', + '
            ' ), $s ); $s = str_replace ( array ( - '{{|-<-|}}ol{{|->-|}}', - '{{|-<-|}}ol/{{|->-|}}' + '{{|-<-|}}ol{{|->-|}}', + '{{|-<-|}}ol/{{|->-|}}' ), array ( - '
              ', - '
                ' + '
                  ', + '
                    ' ), $s ); $s = str_replace ( array ( - '{{|-<-|}}pre{{|->-|}}', - '{{|-<-|}}pre/{{|->-|}}' + '{{|-<-|}}pre{{|->-|}}', + '{{|-<-|}}pre/{{|->-|}}' ), array ( - '
                    ',
                    -      '
                    '
                    +          '
                    ',
                    +          '
                    '
                       ), $s );
                    -
                    +  
                       // cleanup
                       $s = str_replace ( array (
                    -      '{{|-',
                    -      '-|}}'
                    +          '{{|-',
                    +          '-|}}'
                       ), array (
                    -      '',
                    -      ''
                    +          '',
                    +          ''
                       ), $s );
                    -
                    +  
                       return $s;
                     }
                     function linkify($input) {
                       $pattern = '@(http(s)?://)?(([a-zA-Z])([-\w]+\.)+([^\s\.]+[^\s]*)+[^,.\s])@';
                       return $output = preg_replace ( $pattern, '$0', $input );
                     }
                    -=======
                    -'
                    -  ), 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;
                    +function inStr($needle, $haystack) {
                    +  if (strpos ( $haystack, $needle ) !== false) {
                    +    return true;
                       }
                       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 .= '
                      '; - $lv ++; - } - while ( $lv > $nlv ) { - $text .= '
                    '; - $lv --; - } - } - if (startsWith ( $t, '!!!!! ' )) { - $t = '
                    ' . substr ( $t, 6 ) . '
                    '; - } - if (startsWith ( $t, '!!!! ' )) { - $t = '

                    ' . substr ( $t, 5 ) . '

                    '; - } - if (startsWith ( $t, '!!! ' )) { - $t = '

                    ' . substr ( $t, 4 ) . '

                    '; - } - if (startsWith ( $t, '!! ' )) { - $t = '

                    ' . substr ( $t, 3 ) . '

                    '; - } - if (startsWith ( $t, '! ' )) { - $t = '

                    ' . substr ( $t, 2 ) . '

                    '; - } - if ($lv == 0) { - $r .= $t; - } else { - $r .= '
                  1. ' . $t . '
                  2. '; - } - // var_dump ( $t ); - } - while ( $lv > 0 ) { - $r .= '
          '; - $lv --; - } - return $r; -} -function onlySimpleHTML($s) { - $s = str_replace ( array ( - '<', - '>' - ), array ( - '{{|-<-|}}', - '{{|->-|}}' - ), $s ); - $s = str_replace ( array ( - '{{|-<-|}}b{{|->-|}}', - '{{|-<-|}}b/{{|->-|}}' - ), array ( - '', - '' - ), $s ); - $s = str_replace ( array ( - '{{|-<-|}}u{{|->-|}}', - '{{|-<-|}}u/{{|->-|}}' - ), array ( - '', - '' - ), $s ); - $s = str_replace ( array ( - '{{|-<-|}}i{{|->-|}}', - '{{|-<-|}}i/{{|->-|}}' - ), array ( - '', - '' - ), $s ); - $s = str_replace ( array ( - '{{|-<-|}}span{{|->-|}}', - '{{|-<-|}}span/{{|->-|}}' - ), array ( - '', - '' - ), $s ); - $s = str_replace ( array ( - '{{|-<-|}}b{{|->-|}}', - '{{|-<-|}}b/{{|->-|}}' - ), array ( - '', - '' - ), $s ); - $s = str_replace ( array ( - '{{|-<-|}}br{{|->-|}}', - '{{|-<-|}}br/{{|->-|}}' - ), array ( - '
          ', - '
          ' - ), $s ); - $s = str_replace ( array ( - '{{|-<-|}}h1{{|->-|}}', - '{{|-<-|}}h1/{{|->-|}}' - ), array ( - '

          ', - '

          ' - ), $s ); - $s = str_replace ( array ( - '{{|-<-|}}h2{{|->-|}}', - '{{|-<-|}}h2/{{|->-|}}' - ), array ( - '

          ', - '

          ' - ), $s ); - $s = str_replace ( array ( - '{{|-<-|}}h3{{|->-|}}', - '{{|-<-|}}h3/{{|->-|}}' - ), array ( - '

          ', - '

          ' - ), $s ); - $s = str_replace ( array ( - '{{|-<-|}}h4{{|->-|}}', - '{{|-<-|}}h4/{{|->-|}}' - ), array ( - '

          ', - '

          ' - ), $s ); - $s = str_replace ( array ( - '{{|-<-|}}h5{{|->-|}}', - '{{|-<-|}}h5/{{|->-|}}' - ), array ( - '

          ', - '
          ' - ), $s ); - $s = str_replace ( array ( - '{{|-<-|}}h6{{|->-|}}', - '{{|-<-|}}h6/{{|->-|}}' - ), array ( - '
          ', - '
          ' - ), $s ); - $s = str_replace ( array ( - '{{|-<-|}}li{{|->-|}}', - '{{|-<-|}}li/{{|->-|}}' - ), array ( - '
        • ', - '
        • ' - ), $s ); - $s = str_replace ( array ( - '{{|-<-|}}ul{{|->-|}}', - '{{|-<-|}}ul/{{|->-|}}' - ), array ( - '
            ', - '
              ' - ), $s ); - $s = str_replace ( array ( - '{{|-<-|}}ol{{|->-|}}', - '{{|-<-|}}ol/{{|->-|}}' - ), array ( - '
                ', - '
                  ' - ), $s ); - $s = str_replace ( array ( - '{{|-<-|}}pre{{|->-|}}', - '{{|-<-|}}pre/{{|->-|}}' - ), array ( - '
                  ',
                  -      '
                  '
                  -  ), $s );
                  -
                  -  // cleanup
                  -  $s = str_replace ( array (
                  -      '{{|-',
                  -      '-|}}'
                  -  ), array (
                  -      '',
                  -      ''
                  -  ), $s );
                  -
                  -  return $s;
                  -}
                  ->>>>>>> branch 'master' of https://git.seemsleg.it/pub/php-func-lib
                   ?>
                  \ No newline at end of file