Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 400515
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T16:56:54+00:00 2026-05-12T16:56:54+00:00

Ive got a string that are words bunched together and I need to seperate

  • 0

Ive got a string that are words bunched together and I need to seperate them, and every word that ends in ‘A’ should probably be on a new line,

item onea second itema third

I also need to check if the word ending in ‘A’ should actually end in ‘A’ like extra or sultana.

item oneasecond itemand an extra item

I have an array full of words ending in ‘A’ from this website http://www.morewords.com/ends-with/a so I just need the preg_replace function.

I really am learning everytime someone answers a question here so again thanks for everyones time and patience

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T16:56:55+00:00Added an answer on May 12, 2026 at 4:56 pm

    You could do something like this:

    // assoc array keyed on words that end with A
    $endsWithA = array("sultana" => 1, ...); 
    
    $words = split(' ', $string);
    
    $newString = '';
    $finalStrings = array();
    
    foreach ($words AS $w) {    
        // if it ends with a, check to see if it's a real word.
        // if so, end the current string and store it
        if (preg_match("/a$/", $w) && !$endsWithA[$w]) {
            $w = preg_replace("/a$/","", $w);
            $newString .= $w;
            $finalStrings[] = $newString;
            $newString = '';
        }
        else {
            $newString .= $w . ' ';
        }    
    }
    
    // Get any remaining newString
    if ($newString) $finalStrings[] = trim($newString);
    
    print_r($finalStrings);
    

    Haven’t tested it, etc., but it would give you an array $finalStrings populated with the strings split from the original.

    Update: fixed a couple of typos in the code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got wide string and I'm writing it to a wofstream that I opened
I've got an application that's using string.compare(string,string) to sort some values. The thing I
I've got a Clr user defined type that takes a string of values sepertated
I've got a function inside of a class that returns a string. Inside this
I've got a method in a class that's writing to some string, which calls
If I've got an array of values that are basically zero-padded string representations of
So I've got a column in a table that contains a string values (keywords
I've got an OR mapper (iBatis.Net) that returns an IList. // IList<T> QueryForList<T>(string statementName,
I've got a generic dictionary Dictionary<string, T> that I would like to essentially make
I've got a batch of strings that I need to cut down. They're basically

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.