How to Input string get Diamond shape Php

Normal Core PHP simple Input text box get string is viewed diamond shape.

Code:


<form action="" method="post">
Enter the String : <input type="text" name="text" id="text" value="" />
<input type="submit" name="submit" id="submit" value="submit" />
</form>
<?php
error_reporting(0);
$string=$_POST['text'];
$len=strlen($string);
if(isset($_POST['submit']))
{
echo "<center>";
for($i=0;$i<$len;$i++)
{
for($j=0;$j<=$i;$j++)
{
echo $string[$j];
}
echo "<br>";
}
for($l=$i;$l>=0;$l--)
{
for($j=0;$j<$l;$j++)
{
echo $string[$j];
}
echo "<br>";
}
echo "</center>";
}

?>

Output Screen:


phpdiamond



How to Input string get Diamond shape Php Dev2Tricks 5 of 5
Normal Core PHP simple Input text box get string is viewed diamond shape. Code: <form action="" method="post"...

Share this

Related Posts

Previous
Next Post »