Split a string and store into an array

This PHP script code is for split a string into the specified length and store it into an array. Here we are using a form to enter the string to split , length at which split process and the cut mode . In normal cut modes split wont happen in the middle of a single word , in strict mode split will happen strictly even in the middle of a single word.

<form name="split" action="" method="post">
Enter the string to Split
<input type="text" name="text1" /><br />
Enter the character length to split:<input type="text" name="len1" /><br />
Cut Mode;<select name="cut">
<option value=0 t>Normal Cut</option>
<option value=1>Strict Cut</option>
<input type="submit" value="split" name="btnsubmit" />

//echo "Original String ".$text;
//$count= strlen($text);
$newtext = wordwrap($text, $len1, "<***>",$mode);
$result=explode('<***>', $newtext);
$count= count($result);
while ($i<$count)
echo "String ".$i." is : <b>".$result[$i]."</b><br>";
Exit mobile version