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 6774459
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:47:22+00:00 2026-05-26T15:47:22+00:00

I have some text inside $content var, like this: $content = $page_data->post_content; I need

  • 0

I have some text inside $content var, like this:

$content = $page_data->post_content;

I need to slice the content somehow and extract the sentences, inserting each one inside it’s own var.
Something like this:

$sentence1 = 'first sentence of the text';
$sentence2 = 'second sentence of the text';

and so on…

How can I do this?

PS
I am thinking of something like this, but I need somekind of loop for each sentence:

$match = null;
preg_match('/(.*?[?\.!]{1,3})/', $content, $match);  
$sentence1 = $match[1];   
$sentence2 = $match[2]; 

Ty:)

  • 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-26T15:47:23+00:00Added an answer on May 26, 2026 at 3:47 pm

    Assuming a sentence is delimited by terminating punctuation, optionally followed by a space, you can do the following to get the sentences in an array.

    $sentences = preg_split('/[!?\.]\s?/', $content);
    

    You may want to trim any additional spaces as well with

    $sentences = array_map('trim', $sentences);
    

    This way, $sentences[0] is the first, $sentences[1] is the second and so on. If you need to loop through them you can use foreach:

    foreach($sentences as $sentence) {
      // Do something with $sentence...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have, for example, markup like this <div id=content> <p>Here is some wonderful text,
I have some text that is stored in a variable like this: <div class=foo>text
I have a html like this : <h1> Headhing </h> <font name=arial>some text</font></br> some
I have some text i need to filter out a list of bad words
I have some text that uses Unicode punctuation, like left double quote, right single
I have some text in a UITextView, that I would like to have show
I have some code in .Net to draw some text content using GDI+. I
Good day to all. I have this structure <html> <iframe> <div id=idd>Some Content</div> </iframe>
I have some text content (read in from the HTML using jQuery) that looks
I have a div,which content some text content. <div id=con style=position:absolute;left:50px;top:50px;border:1px solid red;font-size:12px;> Text

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.