Jump to content

Recommended Posts

On my website, I am using basic tables and everyone knows if you type something like the following it will stretch the table to unbelievable lengths.

 

Word:

wert23rtw2tergwergwr83dty5754c7n53yv59t7vn358935yhmc5t735ytn75mcn73v5tv78935hym357tvm9357yhc3579thc4tgciwhomhegmvy2893589t3yvn59357y635nic9n5y

 

I want to know if there is an existing function in PHP to break the word when it gets to a certain length.

 

--

DJ

 

Link to comment
https://forums.phpfreaks.com/topic/69416-string-break/
Share on other sites

here you go, i figured out a hack.

first convert your string to "words" with chunk_split  THEN use wordwrap

 

<?php
$longstring = "wert23rtw2tergwergwr83dty5754c7n53yv59t7vn358935yhmc5t735ytn75mcn73v5tv78935hym357tvm9357yhc3579thc4tgciwhomhegmvy2893589t3yvn59357y635nic9n5y";

$maxLength = 50;

$split = chunk_split($longstring,$maxLength);
$wrap = wordwrap($split,$maxLength,"<br>"," ");

echo $wrap;

?>

Link to comment
https://forums.phpfreaks.com/topic/69416-string-break/#findComment-348785
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.