Re: [PHP] sentence case
OK -- dumb question -- what is an OP? ?php /* Stephen Johnson c | eh The Lone Coder http://www.thelonecoder.com [EMAIL PROTECTED] 562.924.4454 (office) 562.924.4075 (fax) continuing the struggle against bad code */ ? From: John Nichel [EMAIL PROTECTED] Date: Wed, 23 Feb 2005 14:13:20 -0500 To: php Mailing Lists php-general@lists.php.net Subject: Re: [PHP] sentence case What if the OP doesn't like touching worms? ;) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] sentence case
Stephen Johnson wrote: OK -- dumb question -- what is an OP? Original Poster -- John C. Nichel ÜberGeek KegWorks.com 716.856.9675 [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] sentence case
[snip] with php, HOW CAN I CONVERT SENTENCES LIKE THIS . TO BE UPPER AND LOWER CASE to become like this : How can I convert sentences like this. To be upper and lower case. [/snip] http://www.php.net/ucfirst -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] sentence case
Diana Castillo wrote: with php, HOW CAN I CONVERT SENTENCES LIKE THIS . TO BE UPPER AND LOWER CASE to become like this : How can I convert sentences like this. To be upper and lower case. Sounds like you need a combination of ucfirst() and strtolower(). $newstring = ucfirst(strtolower($oldstring)); -- Aaron Gould Programmer/Systems Administrator PARTS CANADA -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] sentence case
Hello Jay, Wednesday, February 23, 2005, 11:05:51 AM, you wrote: How can I convert sentences like this. To be upper and lower case. J http://www.php.net/ucfirst That won't work because it'll only capitalize the first letter of the string. Since his string contains more than one sentence he needs to be able to capitalize the first letter of each sentence. I'm thinking something like: 1. strtolower() the string 2. explode() on the period 3. Loop through the resulting array a. trim() whitespace on each element b. ucfirst() on each element of the array c. Concatenate the string back together, putting a period and a space at the end of each element. That's the long way. Anyone know the shortcut! grin -- Leif (TB lists moderator and fellow end user). Using The Bat! 3.0.2.3 Rush under Windows XP 5.1 Build 2600 Service Pack 2 on a Pentium 4 2GHz with 512MB -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] sentence case
Leif Gregory mailto:[EMAIL PROTECTED] on Wednesday, February 23, 2005 10:31 AM said: I'm thinking something like: 1. strtolower() the string 2. explode() on the period 3. Loop through the resulting array a. trim() whitespace on each element b. ucfirst() on each element of the array c. Concatenate the string back together, putting a period and a space at the end of each element. And on top of that he'll need to convert all 'i' to 'I' because of step 1. Chris. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] sentence case
[snip] That won't work because it'll only capitalize the first letter of the string. Since his string contains more than one sentence he needs to be able to capitalize the first letter of each sentence. [/snip] I was teaching the OP to fish instead of baiting the hook for her. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] sentence case
Chris W. Parker wrote: Leif Gregory mailto:[EMAIL PROTECTED] on Wednesday, February 23, 2005 10:31 AM said: I'm thinking something like: 1. strtolower() the string 2. explode() on the period 3. Loop through the resulting array a. trim() whitespace on each element b. ucfirst() on each element of the array c. Concatenate the string back together, putting a period and a space at the end of each element. And on top of that he'll need to convert all 'i' to 'I' because of step 1. ... and to be really picky, convert common acronyms to upper-case as well. :-) That chould be done with str_replace and arrays for 'find' and 'replace' - the challenge is to come up with the list of acronyms... $find = array('stfu', 'rtfm', 'lol'); $replace = array('STFU', 'RTFM', 'LOL'); $replaced_string = str_replace($find, $replace, $old_string); Of course, se notice that the content of $replace is the same as $find, but upper-cased. Is there a more elegant solution? /Mattas -- More views at http://www.thorslund.us -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] sentence case
Jay Blanchard wrote: [snip] That won't work because it'll only capitalize the first letter of the string. Since his string contains more than one sentence he needs to be able to capitalize the first letter of each sentence. [/snip] I was teaching the OP to fish instead of baiting the hook for her. What if the OP doesn't like touching worms? ;) -- John C. Nichel ÜberGeek KegWorks.com 716.856.9675 [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] sentence case
Hello Chris, Wednesday, February 23, 2005, 11:49:32 AM, you wrote: C And on top of that he'll need to convert all 'i' to 'I' because of C step 1. You and Mattias both have valid points. The only other thing I can think of is a regexp that is searching for a period and a space then does a ucwords() on the following word, but that's a lot of work to pull things apart like that! grin -- Leif (TB lists moderator and fellow end user). Using The Bat! 3.0.2.3 Rush under Windows XP 5.1 Build 2600 Service Pack 2 on a Pentium 4 2GHz with 512MB -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] sentence case
Leif Gregory wrote: Hello Chris, Wednesday, February 23, 2005, 11:49:32 AM, you wrote: C And on top of that he'll need to convert all 'i' to 'I' because of C step 1. You and Mattias both have valid points. The only other thing I can think of is a regexp that is searching for a period and a space then does a ucwords() on the following word, but that's a lot of work to pull things apart like that! grin Could be done, still. Oh, and sentences may end with other characters, too. Notably ! and ?. -- More views at http://www.thorslund.us -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] sentence case
Hello Mattias, Wednesday, February 23, 2005, 12:35:21 PM, you wrote: M Oh, and sentences may end with other characters, too. Notably ! M and ?. Nuh-u Prove it!(Oh dang..) grin -- Leif (TB lists moderator and fellow end user). Using The Bat! 3.0.2.3 Rush under Windows XP 5.1 Build 2600 Service Pack 2 on a Pentium 4 2GHz with 512MB -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] sentence case
Diana Castillo wrote: with php, HOW CAN I CONVERT SENTENCES LIKE THIS . TO BE UPPER AND LOWER CASE to become like this : How can I convert sentences like this. To be upper and lower case. here is something I hacked together for Smarty once, modified a bit to suit your need more (syntax-checked only), maybe it gives you some more to go on: function ucsentence($string, $lower = false /* dont think this is a good idea*/) { if ((boolean)$lower) { $string = strtolower($string); } // find this $find = array('/e\.g(\. | )/i', '/i\.e(\. | )/i', '/q\.e\.d(\. | )/i', '/ i /i'); // replace with this temporarily $temp = array('::EG::.','::IE::.','::QED::.', '::I::.'); // replace temp with this at end of processing $repl = array('e.g. ', 'i.e. ', 'q.e.d. ', ' I '); // filter out 'e.g's and other text 'atoms' that contain fullstops that do not // denote the end of a sentence. $string = preg_replace($find, $temp, $string); // find sentences $sentences = preg_split(/(\!(\s)?|\.(\s)?|\?(\s)?)/,$string, -1,PREG_SPLIT_DELIM_CAPTURE); // build the output string. foreach($sentences as $k = $sentence) { if (in_array(trim($sentence), array('.','?','!'))) { continue; } $sentences[ $k ] = ucfirst(trim($sentence)); } // put the 'e.g.'s back etc $string = str_replace($temp, $repl, join('', $sentences)); return $string; } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php