View difference between Paste ID: 4NnBwbNQ and aUudug0U
SHOW: | | - or go back to the newest paste.
1
<?php
2
 function CheckString($regex, $str)
3
4
    {
5
6
      if(@!ereg("^[^". $regex . "]*$", $str)) return true; 
7
8
      else return false;
9
10
    }
11
12
13
  $string = "Tohle je velice dlouhy text."; // String, který chcete zkrátit
14
  $lenght = 12; // Maximální délka stringu
15
  $disallow = ".:!?";
16
  $String2 = null;
17
  $a = 0;
18
  while(true){
19
    $String2 .= $string[$a];
20
    $a++;
21
    if($a > $lenght){
22-
      if(CheckString($disallow, $string[$a])){
22+
      if(CheckString($disallow, $string[$a]) || $string[$a] == " "){
23
        break;
24-
      }elseif($string[$a] == " "){
24+
25
    }
26
  }  
27
  $String2 .= "...";
28
  echo $String2; //vypíšeme
29
30
?>