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.

<html>
<head>
</head>
<body>
<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>
</select><br>
<input type="submit" value="split" name="btnsubmit" />

</form>
<?php
if(isset($_POST['btnsubmit']))
{
$text=$_POST['text1'];
$len1=$_POST['len1'];
$mode=$_POST['cut'];
//echo "Original String ".$text;
//$count= strlen($text);
$newtext = wordwrap($text, $len1, "<***>",$mode);
$result=explode('<***>', $newtext);
$count= count($result);
$i=0;
while ($i<$count)
{
echo "String ".$i." is : <b>".$result[$i]."</b><br>";
$i=$i+1;
}
}
?>
</body>
</html>

Here you can watch this script in action VIEW

A prime number is defined as a number which can be only divisible by 1 and that number itself. That number cannot be divisible by any other number. So if we try to divide that number by any other number between one and that number , we will get a remainder. According to the prime number definition number one ( 1 ) wont consider as a primer number. The smallest primer number is 2 .

See is a list of primer number below 50
2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47,

Here is a sample PHP script program to create a list of prime numbers
In this example we are going to print first 20 prime numbers.

<?php
$count = 0 ;
$number = 2 ;
while ($count < 20 )
{
$div_count=0;
for ( $i=1;$i<=$number;$i++)
{
if (($number%$i)==0)
{
$div_count++;
}
}
if ($div_count<3)
{
echo $number." , ";
$count=$count+1;
}
$number=$number+1;
}
?>

Its output will be :

2 , 3 , 5 , 7 , 11 , 13 , 17 , 19 , 23 , 29 , 31 , 37 , 41 , 43 , 47 , 53 , 59 , 61 , 67 , 71 ,

Logic of this program : We need first store the current number to a variable. And then we will find the remainder for each division of other numbers with the stored number using a loop. And we will increment a counter if remainder found zero. After all the division operations with other numbers we will check the total counter for the remainder. If its value greater than two means , that number can be divisible by some other number instead of 1 and that number itself.If its value less than three means , its a primer number.

Now look at another PHP script for generating a list of prime numbers below 100.

<?php
$number = 2 ;
while ($number < 100 )
{
$div_count=0;
for ( $i=1;$i<=$number;$i++)
{
if (($number%$i)==0)
{
$div_count++;
}
}
if ($div_count<3)
{
echo $number." , ";
}
$number=$number+1;
}
?>

Its output will be ;

2 , 3 , 5 , 7 , 11 , 13 , 17 , 19 , 23 , 29 , 31 , 37 , 41 , 43 , 47 , 53 , 59 , 61 , 67 , 71 , 73 , 79 , 83 , 89 , 97 ,

This not only the one method of logic to create Primer number series .. You can create the list other methods and loops in PHP.

A Fibonacci Series of numbers will look like
0 , 1 , 1 , 2 , 3 , 5 , 8 , 13 , 21 , 34 , 55

First two Fibonacci numbers are 0 and 1 . After that each number will be the sum of previous two numbers . Here we can see that third Fibonacci number is 1 ( sum of first two numbers 0 + 1 ) , and fourth Fibonacci number will be the sum of third and second number ( 1 + 1 = 2 ) , and fifth Fibonacci number will be the sum of fourth and third number ( 2 + 1 = 3 ). The series will go like that infinity .

Now we can learn how to make a Fibonacci series using PHP .
Here is the PHP script for printing first 20 Fibonacci numbers .

<?php
$count = 0 ;
$f1 = 0;
$f2 = 1;
echo $f1." , ";
echo $f2." , ";
while ($count < 20 )
{
$f3 = $f2 + $f1 ;
echo $f3." , ";
$f1 = $f2 ;
$f2 = $f3 ;
$count = $count + 1;
}
?>

Its output will be :

0 , 1 , 1 , 2 , 3 , 5 , 8 , 13 , 21 , 34 , 55 , 89 , 144 , 233 , 377 , 610 , 987 , 1597 , 2584 , 4181 , 6765 , 10946 ,

In this example I have created the series using a while loop .Like this we can make Fibonacci Series using for loops also in PHP .