nemec Posted October 21, 2005 Report Share Posted October 21, 2005 kaa var apgriezt garus vaardus??? piemeeram lielaakus par 32 simboliem Link to comment Share on other sites More sharing options...
AcidRain Posted October 21, 2005 Report Share Posted October 21, 2005 (edited) function check_input($input, $maxlenght= 32) $temp_array = explode(" ", $input); foreach ($temp_array as $word) { if (strlen($word) > $maxlenght) { return false; } } return true; } Piemērs: if (!check_input($_POST['message'])) { echo 'One of your words in your message in longer than 32 chars. Please edit your message.'; } http://lv.php.net/manual/en/function.strlen.php#54846 Edited October 21, 2005 by AcidRain Link to comment Share on other sites More sharing options...
php_Stopp Posted October 21, 2005 Report Share Posted October 21, 2005 (edited) <?php if ( strlen($text) > 32 ) { // $text ir vaards for($i=0;$i<32;$i++) { echo $text[$i]; } // paraadiit tikai pirmos 32 simbolus } ?> ja gribi vārdu ierakstīt kaukādā dokumentā, tad if ( strlen($text) > 32 ) { for ($i=0;$i<32;$i++) { fputs(fopen("doc.txt", "w"), $text[$i]); } } Edited October 21, 2005 by php_Stopp Link to comment Share on other sites More sharing options...
Klez Posted October 21, 2005 Report Share Posted October 21, 2005 function stringLimit($string, $length = 50, $ellipsis = '...') { return strlen($fragment = substr($string, 0, $length + 1 - strlen($ellipsis))) < strlen($string) + 1 ? preg_replace('/\s*\S*$/', '', $fragment) . $ellipsis : $string; } ja mekleetu manuaalii tad atrastu. shii ir no manuaalja. Link to comment Share on other sites More sharing options...
php_Stopp Posted October 21, 2005 Report Share Posted October 21, 2005 (edited) AcidRain, tavu piemēru var izdarīt bez jebkādu funkciju taisīšanas: if ( strlen($_POST['text']) > 32 ) echo "paaraak gars"; edit: oops, tur tas tavs kods pārbauda katru vārdu :P Edited October 21, 2005 by php_Stopp Link to comment Share on other sites More sharing options...
nemec Posted October 21, 2005 Author Report Share Posted October 21, 2005 man vajadzeeja AcidRaina piemeeru, tb apgriezt vaardus tekstaa. THX Link to comment Share on other sites More sharing options...
Recommended Posts