Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and the Yahoo Answers website is now in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

PHP function formatting string?

I am trying to take a long string (url) and start a new line <br> after 50 characters, because that is all that fits in my area. I have tried to a few things, but this is getting an integer number for length, splitting the string into an array, so then I can call it by index. I tried modulus and if statement, but they don't seem to get the desired result. I am working with a database, so I can't assume anything, but every 50 characters start a new line. Thanks!

$newText =str_split($text3);

$count = strlen($text3);

for($i=0; $i < $count; $i++){

echo $newText[$i];

}

Update:

I figured it out, just wrap it before I put it into a link. Flawless

$newtext = wordwrap($alert3, 50, "\n", true);

$text3 = "<b><a href=$newtext>$newtext</a></b>";?>

1 Answer

Relevance
  • 8 years ago
    Favorite Answer

    echo implode("<br>", str_split($text,50));

Still have questions? Get your answers by asking now.