Results 1 to 3 of 3

Thread: Editing sentences

  1. #1

    Thread Starter
    Lively Member sridharao's Avatar
    Join Date
    Feb 2007
    Posts
    106

    Editing sentences

    Hello guys, I need a complex editing code. I am displaying user data present in table on a html page. I need a code that does all of the following.

    1. Ensure that first word of a sentence is capital. The sentence may end with . ? or !
    2. Alphabet I should be always capital and never i.
    3. Unless specified, a sentence must end with a period.
    4. There should be a single white space after period, comma or question mark.

    I need one efficient code to do all this. Can anyone do it for me?
    Save trees, avoid plastics, say no to zoo, go veg, recycle as much, live holistic

  2. #2
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: Editing sentences

    This sounds an awful lot like a homework assignment...

    Why don't you try to code it, and someone can help you out when you run into issues?

  3. #3
    Frenzied Member
    Join Date
    Jan 2008
    Posts
    1,754

    Re: Editing sentences

    Read up on Regular Expressions here if you don't already know how to use/write them: http://www.regular-expressions.info/

    After you become familiar with the basics of RegEx you can implement a RegEx replace using preg_replace: http://php.net/manual/en/function.preg-replace.php

    If you use preg_replace_callback you can use ucfirst in the callback to uppercase the first letter of a string: http://php.net/manual/en/function.ucfirst.php

    The general idea is that you use regular expressions to isolate each sentence. You then use ucfirst on each sentence to make sure the first letter of the sentence is capitalized. Your regex can also isolate occurances of the letter 'i' so that you may capitalize it. You could also use a str_replace for the letter 'i'.

    str_replace and preg_replace can both deal with that extra white space after the sentence.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width