jam Posted October 4, 2005 Report Share Posted October 4, 2005 Ir strings, kuram vajag visus vārda pirmos burtus kapitalizēt iz'nemot saikļus and un are utt. $teksts = "bannanas_and_apples_are_fruits"; $str = ucwords(str_replace("_"," ",$teksts)); echo $str; // Bannanas And Apples Are Fruits varbūt kāds var on the fly uzrakstīt, kā lai And un Are paliktu lowerkeisā? Paldies. Link to comment Share on other sites More sharing options...
Robis Posted October 4, 2005 Report Share Posted October 4, 2005 njaa... Tiešām grūti izdomāt? Link to comment Share on other sites More sharing options...
Delfins Posted October 4, 2005 Report Share Posted October 4, 2005 ucfirst() + preg_replace_callback() Link to comment Share on other sites More sharing options...
Delfins Posted October 4, 2005 Report Share Posted October 4, 2005 iz'nemot saikļus and un are utt.unecho $str; // Bannanas And Apples Are Fruits jau ir pretrunā.... ja ņem izejas tekstu Link to comment Share on other sites More sharing options...
jam Posted October 4, 2005 Author Report Share Posted October 4, 2005 Robi, tevi kāds pušu plēš? Ja negribi neko loģisku rakstīt, tad sēdi un rubini degunu vai trennē labo roku, gan kāds, kuram nav par grūtu, kaut ko jēdzīgu uzrakstīs. Link to comment Share on other sites More sharing options...
Delfins Posted October 4, 2005 Report Share Posted October 4, 2005 (edited) <?php $text = "bannanas and apples are fruits"; function ucword_callback( $m ) { return ( !in_array($m[0], Array('are','and') ) ) ? ucfirst($m[0]) : $m[0]; } function ucword( $text ) { $sp = '/([^\s]+)/i'; return preg_replace_callback( $sp, 'ucword_callback', $text ); } print ucword($text); ?> Edited October 4, 2005 by Delfins Link to comment Share on other sites More sharing options...
jam Posted October 4, 2005 Author Report Share Posted October 4, 2005 Paldies Tev Delfin, tu esi laba zivs :) Link to comment Share on other sites More sharing options...
bubu Posted October 4, 2005 Report Share Posted October 4, 2005 Delfīni nav zivis. Link to comment Share on other sites More sharing options...
Delfins Posted October 4, 2005 Report Share Posted October 4, 2005 tieš tā, bioloģiju skolā bij jāmācās :) Link to comment Share on other sites More sharing options...
jam Posted October 5, 2005 Author Report Share Posted October 5, 2005 Pardon, Delfin, tu esi labs zivjizskata zīdītājs :)) Link to comment Share on other sites More sharing options...
Roze Posted October 5, 2005 Report Share Posted October 5, 2005 Var tak vienkāršāk ne? $str = ucwords($teksts); $str = str_replace('And','and',$str); $str = str_replace('Are','are',$str); vai $trans = array('And' => 'and', 'Are' => 'are'); $str = strtr(ucwords($str), $trans); ja izvirst tad .. bez visiem callbackiem utt utprj.. Bet ja pieņem tiek koriģēti teikumi ko darīt ja 'are' vai 'and' ir teikuma sākuma (and diezvai bet Are jautājumā var noteikti būt)? :) Link to comment Share on other sites More sharing options...
bubu Posted October 5, 2005 Report Share Posted October 5, 2005 And then we walked home. Vai nav normāls teikums? Link to comment Share on other sites More sharing options...
Roze Posted October 5, 2005 Report Share Posted October 5, 2005 And then we walked home.Vai nav normāls teikums? 24027[/snapback] Vot nezinu kā angliski, bet latviski sākt teikumu ar 'un' ir slikts stils ;) Link to comment Share on other sites More sharing options...
Delfins Posted October 5, 2005 Report Share Posted October 5, 2005 `grāmats stilam` ir ok ;) PS: _callback arī mācēs arī citu ko izdarīt, ja vajag... Link to comment Share on other sites More sharing options...
Roze Posted October 5, 2005 Report Share Posted October 5, 2005 `grāmats stilam` ir ok ;) PS: _callback arī mācēs arī citu ko izdarīt, ja vajag... 24033[/snapback] Vot nez kā ar to pirmā vārda detektēšanu teikumā.. Link to comment Share on other sites More sharing options...
Recommended Posts