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

  • Home
  • SEARCH
  • 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 8469209
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T16:09:35+00:00 2026-06-10T16:09:35+00:00

I am using Markdown to render a rich content on a page, using PHP.

  • 0

I am using Markdown to render a rich content on a page, using PHP. For the brief version, I think it would be fine to truncate the content till second paragraph, or technically, after two \r\n have crossed. So I used this code:

substr($content, 0, strpos($content, "\r\n\r\n", strpos($content, "\r\n\r\n") + 1));

Since the count of \r\n is hard coded, and is also calculated in a weird way, (using +1 after the first position and stuff), is there a better way I can make a function, which says limitContent($content, $lines = 2) and passing the number of lines to the $lines parameter, as by default, it truncates to two lines?

My current code is:

/**
 * Break down the content of Markdown upto 2 breaks. 
 * @param string Markdown String
 * @return string Markdown String upto 2 breaks
 */
function limitContent($content)
{
    return substr($content, 0, strpos($content, "\r\n\r\n", strpos($content, "\r\n\r\n") + 1));
}

Thanks in advance.

  • 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-06-10T16:09:37+00:00Added an answer on June 10, 2026 at 4:09 pm

    Ok, I misunderstood. Is this what you want?

    function limitContent($content, $lines=2)
    {
        $tmp=explode("\r\n\r\n", $content);
        $tmp=array_slice($tmp,0,$lines);
        return implode("\r\n", $tmp);
    }
    

    [edit]
    And slightly better would be:

    function limitContent($content, $lines=2)
        {
            $tmp=explode("\r\n\r\n", $content, $lines+1);
            unset($tmp[$lines]);
            return implode("\r\n", $tmp);
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using PHP Markdown (version 1.0.1n, updated October 2009) to display text saved to
So I'm using Markdown to format text input from user: http://michelf.com/projects/php-markdown/ But I'm doing
I'm using http://michelf.com/projects/php-markdown/ for my markdown library and my question is that if i
I would like to format a table using using markdown extra / html. I
I'm using the Markdown library for PHP by Michel Fortin. Setup is easy and
I'm a huge fan of Markdown (using it in nearly all of my PHP
I'm using marked on the client side to render markdown code to html. But
@post.body has following content (which is converted from Markdown by using RDiscount).How should I
I'm using PHP markdown but I also need a script to convert plaintext links
I was using Markdown for a while for formatting rich contents. Then I needed

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.