1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Split sentence on half

Discussion in 'PHP & Perl' started by Chris Devon, Feb 26, 2009.

  1. Chris Devon

    Chris Devon Jr. VIP Jr. VIP Premium Member

    Joined:
    Jul 2, 2008
    Messages:
    507
    Likes Received:
    192
    I have a problem. I need to split a sentence on half.
    Here is the example:

    "All code must be placed within the appropriate CODE tags!"

    So when it's split it will be

    String 1: All code must be placed
    String 2: within the appropriate CODE tags!

    Does someone have any idea how to do it?

    I know how to do a normal split in php for that example, but i need to make a script that would work with any sentence. Any help or pointer is appreciated.
     
  2. Chris Devon

    Chris Devon Jr. VIP Jr. VIP Premium Member

    Joined:
    Jul 2, 2008
    Messages:
    507
    Likes Received:
    192
    Solved!
     
  3. aliskorn

    aliskorn Jr. VIP Jr. VIP Premium Member

    Joined:
    Apr 21, 2008
    Messages:
    484
    Likes Received:
    459
    Occupation:
    Psychologist & programmer
    I don`t care for php, but it seems the algo would be something like this :
    1. $sentence = Identify a sentence by "." ,"!" ,"?".
    2. $whitespaces = Identify the number of white spaces in $sentence.
    3. trim sentence by $ whitespaces/2

    You can figure out the details . This is very crude but I hope It`s of some use.

    LE: you posted "Solved" in the same at the same time I posted.
     
    • Thanks Thanks x 2
    Last edited: Feb 26, 2009
  4. Chris Devon

    Chris Devon Jr. VIP Jr. VIP Premium Member

    Joined:
    Jul 2, 2008
    Messages:
    507
    Likes Received:
    192
    That's what i needed back then. The problem was logical. Anyways thanks for the effort