Jump to content

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

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.