Jump to content

string break


DJTim666

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.