Skip to content

Instantly share code, notes, and snippets.

@phpfiddle
Created August 29, 2013 08:08
Show Gist options
  • Save phpfiddle/6375422 to your computer and use it in GitHub Desktop.
Save phpfiddle/6375422 to your computer and use it in GitHub Desktop.
no description
<?php
function stripeWords($para)
{
$final_string="";
$value=4;
$words = explode(" ", $para);
foreach( $words as $value ){
if( strlen($final_string . " " . $value) < 4 ){
if( !empty($final_string) ) $final_string .= " ";
$final_string .= $value;
} else {
break;
}
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
</head>
<body>
<?php
if(isset($_POST['para'])){
$para = stripeWords($_POST['para']);
?>
<h3>Striped Paragraph</h3>
<?php print_r($para); ?>
<?php
} else{
?>
<h3>My form</h3>
<form method="post">
<label>Paragraph</label> <textarea name="para"></textarea><br />
<button id="mysubmit" type="submit">Submit</button><br /><br />
</form>
<?php
stripeWords($para);
}
?>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment