dtq26360 2009-05-13 00:56
浏览 325
已采纳

<br />标签出现在textarea输出中

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>
  1. When I remove the textarea tags for the output it works fine.
  2. When I leave the textarea tags and remove/replace echo trim($string)." "; with "" or 'n' or " ", the
    disappears but I also lose the linebreak
  3. Replace echo trim($string)." "; with echo nl2br($string); then same result as 2.
  4. Replace with echo nl2br($string)." "; then same result as 1.

Would appreciate any help. My noob brain is about to implode.

  • 写回答

7条回答 默认 最新

  • dsceme82487 2009-05-13 01:25
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(6条)

报告相同问题?

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分