Jump to content

preg_split (probably easy)


hoopplaya4

Recommended Posts

Hi,

 

I currently have a string that is well over 100 characters long, and I'm using preg_split to split the array at a whitespace, so that words are not cut in the middle.

 

However, my problem is, that the preg_split is only splitting the first 100 characters, and not any subsequent 100 characters after that.  For example:

 

<?php
$myString = "This is 350 characters long, let's say";
$split = preg_split('/^(.{0,100})\s/', $myString, 0, PREG_SPLIT_DELIM_CAPTURE);  //Notice, I want to split every 100 characters.

$array_shift($split);
print_r($split); // This outputs something like: Array ( [0] => First 100 characters [1] => All other characters, no matter the length of the string.)

 

I am looking for it split in 100 character increments.

 

Any ideas on how I might fix my preg_replace?

 

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/172478-preg_split-probably-easy/
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.