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)."n";
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).”n”; with “r” or ‘n’ or “nr”, the
disappears but I also lose the linebreak - Replace echo trim($string).”n”; with echo nl2br($string); then same result as 2.
- Replace with echo nl2br($string).”n”; then same result as 1.
Would appreciate any help. My noob brain is about to implode.
I’ll preface this by saying I use Blogger not WordPress but I imagine there are similarities. In Blogger there is a setting to convert line breaks into
<br>
tags. I guess it’s convenient if you’re not putting code snippets and the like in (if you’re blogging about cats or something) but not so much for programming. I had to turn it off and put in my paragraph tags, etc manually.Here is one less than ideal solution, which also mentions the issue of WordPress inserting
<br>
tags in forms.I think the
<br />
tag is what you want in this case. Newline characters like n and r don’t do anything in HTML – all whitespace, including newlines, is ignored. The<br />
tag is essentially the HTML equivalent – it stands for “break”. I don’t know too much about PHP specifically, so I don’t know why it’s putting the<br />
there for you automatically, but that’s the correct HTML for what you’re describing.Technically, there are better ways to format your output then using those tags, but that’s more of an advanced topic. If you are a bit new to this, like you said, then just get it working this way for now, and then maybe sometime down the road you can learn about proper semantic HTML markup, CSS styling, etc.
Try using this, I already test it…
why not display the results on a
<div>
perhaps or a<p>
??I believe
n
should work. Perhaps you do not have or have an incorrect doctype.Example:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
If all else, I like lock’s answer. You could us a
<div>
and you could even style it to look similar to a<textarea>
(or even better!)It took some looking, but after some time I was able to pinpoint these two locations (lines 154 & 165 – WP 2.8) in the wp-includes/formatting.php file.
This took care of the paragraph and and break tags in my textarea field.
I solved my problem by using strip_tags function. when user would edit the past post, it was saving
in the database and displaying on the blog. But strip_tags function took care of it.