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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:47:53+00:00 2026-05-24T20:47:53+00:00

I have to insert a <br> tag after every 52 words so that it

  • 0

I have to insert a <br> tag after every 52 words so that it displays a line break otherwise the paragraph keeps going on and on increasing its width rather that the height. If there is any other, better way, please tell me.

My code

<?php

$str = "Hello world. My name is Yash Mathur and I am a student. 
        I need help in this question as this is getting on my nerves, so I came to 
        stackoverflow.com 
        to seek for an answer. Please help me insert a line break after every 52 characters. 
        Thanks in advance!";
$len = strlen($str);
if ($len > 52) {
    $str = substr($str, 0, 52) . "<br>";
}
echo $str;
?>

I need to somehow put this in a loop to insert the <br> tag every 52 characters.

  • 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-24T20:47:54+00:00Added an answer on May 24, 2026 at 8:47 pm

    I assume what you are trying to achieve in the end, is just a decent-looking paragraph, whose line-length is not too long, as to become hard to read. I believe this is a cosmetic issue, that can be better addressed in the presentation layer of your application, i.e. the style sheet.

    In the style belonging to the paragraph, you could just add a “width:250px” (250px is an arbitrary value) to constrain the text into a self-wrapping box that is defined by the width of the paragraph.

    I would not do it in PHP unless there is a really valid reason for this, because, if you ever need to change the look of your paragraph, you would then have to delve into your PHP code. This might seem trivial now, but in a couple months you probably will not even remember writing such code in the first place. This will lead to a minor headache at best, and a great deal of wasted time searching for just this formatting function.

    Please rethink your strategy.

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

Sidebar

Related Questions

I have an INSERT query that is pulling data from two tables and inserting
I have an insert query that gets generated like this INSERT INTO InvoiceDetail (LegacyId,InvoiceId,DetailTypeId,Fee,FeeTax,Investigatorid,SalespersonId,CreateDate,CreatedById,IsChargeBack,Expense,RepoAgentId,PayeeName,ExpensePaymentId,AdjustDetailId)
HI, I have an insert statement in a Stored Procedure that requires the value
I have created the following tables in SQLite3 to tag items (after reading this
I have a textarea and among free text input I insert some tags that
I have to insert a string after a certain character using Ruby. For example,
I have logic to insert a tag in a contenteditable div. I want to
I need to insert a div in the DOM after the html tag. It
Say I have file A, in middle of which have a tag string #INSERT_HERE#.
I have two insert statements, almost exactly the same, which run in two different

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.