Reputation: 3
i want to explode one phrase from textarea and near the words , number of characters
$char = $_POST['textarea'];
print_r (explode ( " " ,$char));
for($i = 0 ; $i<count($char) ;$i++)
{
echo $char . " - " . strlen($char) . "<br>" ;
}
it displays : Array ( [0] => hello [1] => there ) hello there - 11 i want one line for each word
Upvotes: 0
Views: 117
Reputation: 4565
Rewrite the code a bit. What you're missing is, you're printing the $char exploding, but not storing it. Corrected code below:
$char = $_POST['textarea'];
print_r (explode ( " " ,$char));
$char = explode(" ",$char); // I've added this line
for($i = 0 ; $i<count($char) ;$i++)
{
echo $char[$i] . " - " . strlen($char[$i]) . "<br>" ; //We are printing $i'th string of $char, as $char is an array of strings now.
}
Upvotes: 2
Reputation: 5012
Try this
$char = explode ( " " ,$char);
$char[$i] . " - " . strlen($char[$i])."<br>";
Upvotes: 4
Reputation: 350
I'm not too sure on what your question is, but if you're using
it should break to a new line in HTML. If you are using the console or a plain text webpage then you will have to append "\n"
Upvotes: 0