nirvair
nirvair

Reputation: 4180

After getting substring from a string, get the rest of the string that was cut

I have a variable that contains string which may or may not contains more than 350 characters.

so to get the first 350 characters, I can use *substr()* to get the first 350 characters

$mainString = "Content which is greater than or less than 350 characters";
$subString = substr($mainString, 0, 350);

This gives me first 350 characters. Now I need those characters after 350th index, let's say from 351 to 400.

How do I get the remaining?

One logic that I had was, to get the length of the string and use substr to get characters from 350 to the strlen($mainString)

Upvotes: 1

Views: 1113

Answers (1)

Alex Wiebogen
Alex Wiebogen

Reputation: 352

$mainString = "Content which is greater than or less than 350 characters";
$cutPos = 350;

$subString = substr($mainString, 0, $cutPos);
$restofString = substr($mainString, $cutPos, strlen($mainString));

Upvotes: 3

Related Questions