Skip to content

Instantly share code, notes, and snippets.

@rohankhudedev
Created November 14, 2021 13:50
Show Gist options
  • Save rohankhudedev/4fbe355150477fe4a8919013212bf43f to your computer and use it in GitHub Desktop.
Save rohankhudedev/4fbe355150477fe4a8919013212bf43f to your computer and use it in GitHub Desktop.
<style>
div,p{
display:inline; /*Added to avoid confusion in outpu*/
}
</style>
<form method="POST">
<textarea name="html_input" required ><?php echo !empty($_POST['html_input'])?$_POST['html_input']:'';?></textarea>
<input type="submit">
</form>
<?php
$wrapper = 4;
if(!empty($_POST['html_input']))
{
$html = explode(PHP_EOL, trim($_POST['html_input']));
$lines = count($html);
echo $lines.'<br/><br/>';
if($lines<=5)
{
$wrapper = $lines-1;
$rem = 0;
$break_at = 1;
}
else if($lines<=15)
{
//5, 6, 7, 10, 11, 15
if(in_array($lines, [6, 7, 10, 11, 15]))
$break_at = floor($lines/$wrapper);
else
$break_at = floor($lines/$wrapper)-1;
$rem = $lines%5;
}
else
{
$break_at = floor($lines/$wrapper)-1;
$rem = ($lines%$wrapper);
}
for($i=0,$break=1; $i<$lines; $i++,$break++)
{
echo $html[$i].'<br/>';
if(($break % $break_at ===0) && $wrapper)
{
if($rem)
{
echo $html[++$i].'<br/>';
$rem--;
}
echo 'Hello<br/>';
$wrapper--;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment