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 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler