hustler Posted November 6, 2006 Report Share Posted November 6, 2006 Lieta ir tāda, ka es gribu, lai tekstu, kas ir garāks par 18 somboliem apgriež un galā pieliek daudzpunktu. Viss it kā elementāri, bet ,piemēram, ja gadās simbols "ā", tad viņš viņu apgriež jau pašā kodā un reuzultātā beigās rādās "?". kā šo atrisināt? Ir idejas? +++ $len = strlen($nosaukums); $z=$nosaukums; if($len>18){$z=substr($nosaukums,0,18)."..."; } Link to comment Share on other sites More sharing options...
andrisp Posted November 6, 2006 Report Share Posted November 6, 2006 paskaties mb_ fjas. (multibyte). Luku mana fja: function crop_string($string, $max_length, $end='...') { if ( mb_strlen($string) > $max_length ) { $string = mb_substr($string, 0, $max_length); return $string.$end; } return $string; } Link to comment Share on other sites More sharing options...
v3rb0 Posted November 6, 2006 Report Share Posted November 6, 2006 ja texts nāk no db, tad var uzriez iekš sql ar left() Link to comment Share on other sites More sharing options...
hustler Posted November 6, 2006 Author Report Share Posted November 6, 2006 paskaties mb_ fjas. (multibyte). Luku mana fja: function crop_string($string, $max_length, $end='...') { if ( mb_strlen($string) > $max_length ) { $string = mb_substr($string, 0, $max_length); return $string.$end; } return $string; } Man viņš neatpazīst tās f-jas: Fatal error: Call to undefined function: mb_strlen() ... Būs tad jāmeģina pa taisno DB. Link to comment Share on other sites More sharing options...
andrisp Posted November 6, 2006 Report Share Posted November 6, 2006 Multibyte fjas ir speciāli jāeneiblo (pareizāk sakot, ir jāielādē speciāls php paplašinājums). http://lv.php.net/manual/en/ref.mbstring.php Papēti php.ini extensions bloku. Link to comment Share on other sites More sharing options...
neprasa Posted November 6, 2006 Report Share Posted November 6, 2006 (edited) a ka uztaisiit maxlengt = 8 charters if $vards >garaks neka $maxlenght die $skaits= count charters vardam $vards echo "parakgars tavs vards satureja : tik simbolus - $skaits"; Edited November 6, 2006 by neprasa Link to comment Share on other sites More sharing options...
andrisp Posted November 6, 2006 Report Share Posted November 6, 2006 Tā arī uztaisi. Visas vajadzīgas fjas jau ir parādītas manis dotajā fjā. Link to comment Share on other sites More sharing options...
neprasa Posted November 6, 2006 Report Share Posted November 6, 2006 $maxlenght = 8; if ( $teksts > $maxlenght ); $lenght = count($teksts); echo"Tavs teksts par garu, un tas satureja $lenght zimes"; izlabojiet Link to comment Share on other sites More sharing options...
andrisp Posted November 6, 2006 Report Share Posted November 6, 2006 Kāpēc pats nevari izlabot ? Kā tu vari salīdzināt stringu $teksts ar integeri $maxlength ? Tu vispār domā līdzi, ko esi uzrakstījis ? $lenght = count($teksts); if ( $length > $maxlenght ) { echo 'Par garu'; } Link to comment Share on other sites More sharing options...
Kavacky Posted November 6, 2006 Report Share Posted November 6, 2006 Stringa garumu ar count mērīt? Smukāk tak ir strlen. :D Link to comment Share on other sites More sharing options...
andrisp Posted November 6, 2006 Report Share Posted November 6, 2006 Ok, es arī nedomāju līdzi :). Pārkārtoju viņa doto tekstu, tāpēc nepiefiksēju. Link to comment Share on other sites More sharing options...
neprasa Posted November 7, 2006 Report Share Posted November 7, 2006 ka uzraksstiit to strlen. un ka vel uztaisit pie read file lai noteikturs vardus replace ar citu vardu Link to comment Share on other sites More sharing options...
andrisp Posted November 7, 2006 Report Share Posted November 7, 2006 "Akdies.." © Delfins. php.net/strlen php.net/str_replace Link to comment Share on other sites More sharing options...
neprasa Posted November 7, 2006 Report Share Posted November 7, 2006 tas ka str replace to saprotu bet ka tiek apzimets faila teksts $fails= "blje.txt"; $saturs = fopen($fails, 'r'); $saturs = str_replace("blje","blja","$saturs"); $saturs = str_replace("na","huj","$saturs"); echo "$saturs"; zinu ka nestradas :( Link to comment Share on other sites More sharing options...
andrisp Posted November 7, 2006 Report Share Posted November 7, 2006 (edited) php.net/fread vai vēl vienkāršāk php.net/file_get_contents PS. ar fopen tu iegūsti tikai referenci uz failu. hmm.. tas ir tikai mainīgais, kurš ir kā shortcut uz šo failu. lai nolasītu saturu tev jāizmanto fread (lai ierakstītu - fwrite). Edited November 7, 2006 by andrisp Link to comment Share on other sites More sharing options...
Recommended Posts