Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <p style="padding: 0 5px;font-size: 14px;font-family:monospace;margin-block-start: 0em;margin-block-end: 0em;" >
- <?php
- function paint($str,$lenght){ #метод окраски слова в зависимости от длины
- $color="#fff";
- if($lenght<4){
- $color="red";
- }
- if($lenght>3 && $lenght<8){
- $color="orange";
- }
- if($lenght>7 && $lenght<12){
- $color="yellow";
- }
- if($lenght>11 && $lenght<16){
- $color="green";
- }
- if($lenght>15 && $lenght<20){
- $color="aqua";
- }
- if($lenght>19 && $lenght<24){
- $color="blue";
- }
- if($lenght>23 && $lenght<27){
- $color="purple";
- }
- if($lenght>26){
- $color="grey";
- }
- $result = "<span style='color:".$color."'>".$str."</span>"."(".$lenght.")";
- return $result;
- }
- function replaceS($str,$lenght){ #метод, который заменяет часть элемента спаном с цветом
- $pattern = "/[\w\s\d]+/u";
- preg_match($pattern,$str,$clearStr); #$clearStr[0] - элемент без знаков препинания или варик с #preg_match_all($pattern,$str,$clearStr);, тогда
- $result = str_ireplace($clearStr[0], paint($clearStr[0],$lenght), $str); #$result = str_ireplace($clearStr[0], paint($clearStr[0][0] иди [0][1],$lenght), $str);
- return $result;
- }
- $text = $_POST["text"];
- $pattern = "/[\w\s\d]+/u"; #паттерн, который убирает все знаки пунктуации
- $list = explode (" ", $text);
- $resultList = array();
- foreach ($list as $key){
- preg_match($pattern,$key,$res);
- $wordLenghtP = iconv_strlen($key); #длина с знаком пунктуации
- $wordLenghtW = iconv_strlen($res[0]);#длина без знаком пунктуации
- $raznica = $wordLenghtP-$wordLenghtW;#количество знаков препинания в элементе
- if($raznica==0)
- array_push($resultList,paint($key,$wordLenghtW));
- else{
- array_push($resultList,replaceS($key,$wordLenghtW));
- }
- }
- foreach ($resultList as $key) {
- echo $key." ";
- }
- ?>
- </p>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement