English 中文(简体)
文本从网页到手稿,然后回网
原标题:Pass block of text from webpage to perl script and then back to web
  • 时间:2011-04-02 07:21:13
  •  标签:
  • html
  • perl
  • cgi

我正在努力做到以下几点。

从网站获取一个用户对TEXTAREA FORM的投入,然后通过一个附件/单,在每一行之前增加线号。 例如:

diet coke
potato chips
gelato

届时将开始

1 diet coke
2 potato chips
3 gelato

我知道,如何将单一价值或一刀切的价值观推向手稿,但当我试图做一个口号(`拉腊y')来增加一个线号时,它就没有工作。 如何做到这一点。

我的html档案

<HTML>
<BODY>

<FORM ACTION="/cgi-bin/splitfoods.pl">
  <P>What did you eat today? <BR><TEXTAREA NAME="value" ID="value" style="width:900px;height
:700px;background-color:#FFF8DC;font-size:20px">
    </TEXTAREA>

<P><INPUT TYPE="SUBMIT" VALUE="Submit">
</FORM>

</BODY>
</HTML>

单体档案(从垫子)

#!/usr/bin/perl

use CGI;
use CGI qw(:standard);


$query = new CGI;

@foods = split( 
 ,$query->param("value"));


# -- HTML STUFF --
print header;
print start_html;
for($i=1; $i<=@foods; $i++) {
    print "$i @foods[$i-1]";
    print "<br>";
}
print end_html;

请求

cgi-bin/splitfoods.pl?value=diet+coke%0D%0Apotato+chips%0D%0Agelato

Thanks

最佳回答
@foods = split( 
 ,$query->param( food ));

for($i=1; $i<=@foods; $i++) {

   print "$i @foods[$i-1]
";

}
问题回答

这是比较清洁的,对近况案例的分类可能性较小。 加上数字是超文本,对网络来说更自然。 确实,你应当读到整个文件CGI,并且总是以警告和严格方式开始代码。

use strict;
use warnings;
no warnings "uninitialized";
use CGI ":standard";

# Scalar/array context matters with param()!
my $food = param("value");
my @foods = split /
/, $food;

print
    header(),
    start_html(),
    ol(li( @foods )),
    end_html();




相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签