Beginner Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOtherBeginner Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old April 24th, 2003, 11:46 AM
mediacolor mediacolor is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Posts: 5 mediacolor User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question HELP: textarea list to a list of html links

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

Reply With Quote
  #2  
Old April 24th, 2003, 06:49 PM
binky's Avatar
binky binky is offline
Gerbil
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Oct 2001
Location: In a Rotastak
Posts: 1,763 binky User rank is Sergeant (500 - 2000 Reputation Level)binky User rank is Sergeant (500 - 2000 Reputation Level)binky User rank is Sergeant (500 - 2000 Reputation Level)binky User rank is Sergeant (500 - 2000 Reputation Level)binky User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 22 h 12 m 52 sec
Reputation Power: 19
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>";
}
__________________
- Sorted!

www.ppfuk.com - Free Photo Sharing

Reply With Quote
  #3  
Old April 24th, 2003, 07:23 PM
Hero Zzyzzx's Avatar
Hero Zzyzzx Hero Zzyzzx is offline
11
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Jul 2001
Location: Lynn, MA
Posts: 4,635 Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 4 Days 23 h 44 m 19 sec
Reputation Power: 77
Send a message via AIM to Hero Zzyzzx
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsOtherBeginner Programming > HELP: textarea list to a list of html links


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT