|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hi...
I need to write a script that will take list from a textarea convert them to a list of html links example microsoft hardware pentium processors has to be converted into <a href="http://www.domain.com/db.cgi?get=microsoft">microsoft</a> <a href="http://www.domain.com/db.cgi?get=hardware">hardware</a> <a href="http://www.domain.com/db.cgi?get=pentium+processors">pentium processors</a> I have whole lists like this that I want to process obviously would like to automate the process. Where do I start? Someone gave me the code <? include(""); $f=popen('listfile','r'); while($line=fgets($f,4096)) { echo '<a href="http://www.domain.com/db.php?keywords='. $line_.'>'. $line_.'</a>'; } ?> but I have no idea how to get this to work with a textarea. I am lost |
|
#2
|
||||
|
||||
|
to get a list delimited by the new line character, use:
$lines = explode("\n", $HTTP_POST_VARS["textareaname"]); you can then cycle through the lines: $x = 0; foreach ($lines as $line) { $links[$x] = "<a href='http://www.domain.com/db.cgi?get=" . $urlencode($line) . "'>" . $line . "</a>"; } |
|
#3
|
||||
|
||||
|
s/$urlencode($line)/urlencode($line)/;
(my php-fu is weak, but I at least spotted that) Here's a perl version if you're interested: Code:
#!/usr/bin/perl
use CGI qw/:standard escape/;
print header();
if (param('submit')){
@words=split(/\n/,param('words'));
foreach $word (@words){
#Get rid of line endings
$word =~ s/[\r\n]+//g;
#Ignore blank lines
$word =~ s/^\s+$//g;
if($word){
print escapeHTML(
a(
{-href=>'http://www.domain.com/db.cgi?get='.escape($word)},$word
)
).br();
}
}
} else {
print start_html(-title=>'One per line, please!'),
h2('Enter the words you want to turn into links one per line please'),
start_form(),
textarea(-name=>'words',-rows=>20,-columns=>40),
br(),
submit(-name=>'submit',-value=>'Submit words [Alt - S]',-accesskey=>'s'),
end_form(),
end_html();
}
Does a little bit of sanity checking and creates the form for you as well. Last edited by Hero Zzyzzx : April 24th, 2003 at 07:29 PM. |
![]() |
| Viewing: Dev Shed Forums > Other > Beginner Programming > HELP: textarea list to a list of html links |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|