Web
STRING
<?php
$mystr="php is a server side scripting language";
echo "<strong> the given string is :</strong> $mystr <br>";
echo "<strong> the length of string is :</strong>".strlen($mystr)."<br>";
echo "<strong> the count of string is :</strong>".str_word_count($mystr)."<br>";
echo "<strong> the reverse of string is :</strong>".strrev($mystr)."<br>";
$substr="side";
echo "<strong> the position of string is '$substr' in the string is :</strong>".strpos($mystr,$substr);
Files
<?php
$fname="file1.txt";
$fptr=fopen($fname,"r");
$content=fread($fptr,filesize($fname));
$fptw=fopen("file2.txt","w");
fwrite($fptw,$content);
echo"<strong>the content copied in file2 is:</strong> <br>".$content;
fclose($fptr);
fclose($fptw);
?>
MERGE
<?php
$f_array=array(25,4,56,35,25,85);
$s_array=array(48,735,52,39);
echo "Elements of array are:<br>";
for ($i=0;$i<count($f_array);$i++)
{
echo $f_array[$i].",";
}
for ($i=0;$i<count($s_array);$i++)
{
echo $s_array[$i].",";
}
$merge_array=array_merge($f_array,$s_array);
echo"<br>Elements of merged array before sorting are:<br>";
for($i=0;$i<count($merge_array);$i++)
{
echo $merge_array[$i].",";
}
rsort($merge_array);
echo"<br> Elements of merged array after sorting are <br>";
for($i=0;$i<count($merge_array);$i++)
{
echo $merge_array[$i].",";
}
?>
PRIME NUMBER
<?php
$number=1;
while($number<50)
{
$div_count=0;
for($i=1;$i<$number;$i++)
{
if(($number%$i)==0)
{
$div_count++;
}
}
if($div_count<=2)
{
echo $number." ,";
}
$number++;
}
?>
Comments
Post a Comment