I have an input form with two textareas allowing a user to type in words separated by commas in each.
<form action="http://www.example.com/output.php" method="post">
<table border="0">
<tr>
<td>
<h3 class="title">Prefix</h3>
<textarea cols="34" rows="8" name="cat[]"></textarea></td>
<td>
<h3 class="title">Suffix</h3>
<textarea cols="34" rows="8" name="cat[]"></textarea></td>
</tr>
</table>
Enter words separated by a comma.
<input type="submit" value="Go" /> </form>
It then passes these to the output form which explodes the words from the commas and then concatenates them together until all possible permutations of the words are created. It then prints out the results into a textarea. My problem is that the output (whilst correctly formatted and have the linebreaks in between each permutation) has a br tag at the end of each line. Eg.
testtest2<br />
testtest2<br />
testtest4<br />
testetest2<br />
testetest2<br />
testetest4<br />
Output form:
$cat = $_POST['cat']; //trait set for textbox inputs
foreach(array_keys($cat) as $key){
$cat[$key] = explode(",", str_replace(' ','',$cat[$key]));
}
function showCombinations($string, $traits, $i)
{
if ($i >= count($traits))
echo trim($string)."
";
else
{
foreach ($traits[$i] as $trait)
showCombinations("$string$trait", $traits, $i + 1);
}
}
?>
<form name=form1 method=post action=''''>
<textarea><?php ShowCombinations('', $cat, 0); ?></textarea>
</form>
- When I remove the textarea tags for the output it works fine.
- When I leave the textarea tags and remove/replace echo trim($string)."
"; with "" or 'n' or "
", the
disappears but I also lose the linebreak - Replace echo trim($string)." "; with echo nl2br($string); then same result as 2.
- Replace with echo nl2br($string)." "; then same result as 1.
Would appreciate any help. My noob brain is about to implode.