Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function CheckString($regex, $str)
- {
- if(@!ereg("^[^". $regex . "]*$", $str)) return true;
- else return false;
- }
- $string = "Tohle je velice dlouhy text."; // String, který chcete zkrátit
- $lenght = 12; // Maximální délka stringu
- $disallow = ".:!?";
- $String2 = null;
- $a = 0;
- while(true){
- $String2 .= $string[$a];
- $a++;
- if($a > $lenght){
- if(CheckString($disallow, $string[$a])){
- break;
- }elseif($string[$a] == " "){
- break;
- }
- }
- }
- $String2 .= "...";
- echo $String2; //vypíšeme
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement