Using URI::Find to detect Web URL's

Ask a Question related to PERL Miscellaneous, Design and Development.

  1. #1

    Default Using URI::Find to detect Web URL's

    A while back I added a post about URL detection. To date I have not been
    able to figure it out. There seems to be very little docu. on this. This is
    what I'm trying to do. I have an html web page with a single textarea form
    named "content" The form action points to my detect.pl script.

    #!/usr/bin/perl
    use URI::Find;

    read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
    @pairs = split(/&/, $buffer);
    foreach $pair (@pairs) {
    ($name, $value) = split(/=/, $pair);
    $value =~ tr/+/ /;
    $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
    $form{$name} = $value;
    }

    $htmlcontent = $form{'content};
    $htmlcontent=~ s/\n/<br>/g; #replaces breaklines with html <br>'s

    <Missing URL detection code goes here>

    open (FILE, ">data/content.txt") or &error("Unable to open");
    flock FILE, 2;
    print FILE $htmlcontent; #final scanned/replaced variable
    close(FILE);

    So basically what I'm looking to do is assign the form data to a variable,
    then scan it for web AND email addressed, and repleace them with the needed
    HTML tags ... <a href ... <mailto ... etc. ect. Then the changed data gets
    saved to a text file, where I use SSI to include the data into my page.
    Points to note would be the form data will almost always contain multipul
    lines and perhaps multipul occurances of web addressed. Can someone please
    help me fill in the missing code? TIA!!!!!

    Randy


    \Dandy\ Randy Guest

  2. Similar Questions and Discussions

    1. URL's in RSS Readers
      I have a movie that pulls sports headlines from the BBC Sports xml feed. I can display the data ok, however, when i click on the stories, i'm not...
    2. opening external url's
      Hey group, just wondering, is there a way to include a link in say, a label or something, and have it as a live link, so when someone clicks on it,...
    3. How do I use url's
      :confused; I am trying to populate a form to be udated using a url. But I don't understand how to get it to pass take a look. I don't know how to...
    4. Tabs Nav Bar Setting Url's ?
      Hi, I think I understand this but I just need someone to confirm it for me. When I set the URL in fireworks MX am I supposed to match the url to...
    5. Hiding URL's...
      I read this article, and thought it was perfect for me... Just the same prob I'm having... http://forums.devshed.com/archive/5/2002/06/2/37330 ...
  3. #2

    Default Re: Using URI::Find to detect Web URL's

    "Dandy" Randy wrote:
    > A while back I added a post about URL detection. To date I have not been
    > able to figure it out. There seems to be very little docu. on this. This is
    > what I'm trying to do. I have an html web page with a single textarea form
    > named "content" The form action points to my detect.pl script.
    >
    > #!/usr/bin/perl
    > use URI::Find;
    >
    > read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
    > @pairs = split(/&/, $buffer);
    > foreach $pair (@pairs) {
    > ($name, $value) = split(/=/, $pair);
    > $value =~ tr/+/ /;
    > $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
    > $form{$name} = $value;
    > }
    >
    > $htmlcontent = $form{'content};
    Amazing, this could be done with 2 lines using CGI.pm. Don't write your
    own decoding stuff.
    > $htmlcontent=~ s/\n/<br>/g; #replaces breaklines with html <br>'s
    >
    > <Missing URL detection code goes here>
    >
    > open (FILE, ">data/content.txt") or &error("Unable to open");
    No need for that & IIRC
    > flock FILE, 2;
    use Fnctl; to make is more readable (named constants instead of 2)
    Also, I guess you should rewind since someone could have added between
    the open and flock IIRC.

    Finally, flock can fail...
    > print FILE $htmlcontent; #final scanned/replaced variable
    > close(FILE);
    You should test if close succeeds. Even print for that matter.
    > So basically what I'm looking to do is assign the form data to a variable,
    I recommend CGI.pm for this
    > then scan it for web AND email addressed, and repleace them with the needed
    > HTML tags ... <a href ... <mailto ... etc. ect. Then the changed data gets
    > saved to a text file, where I use SSI to include the data into my page.
    Sounds dangerous to me.

    --
    Kind regards, feel free to mail: mail(at)johnbokma.com (or reply)
    virtual home: [url]http://johnbokma.com/[/url] ICQ: 218175426
    John web site hints: [url]http://johnbokma.com/websitedesign/[/url]

    John Bokma Guest

  4. #3

    Default Re: Using URI::Find to detect Web URL's

    Eric Schwartz wrote:
    > my $cgi = CGI->new;
    Cool to see others doing this as well. I consider using $query rather
    foolish in most cases :-). Using $cgi promotes self documenting code

    --
    Kind regards, feel free to mail: mail(at)johnbokma.com (or reply)
    virtual home: [url]http://johnbokma.com/[/url] ICQ: 218175426
    John web site hints: [url]http://johnbokma.com/websitedesign/[/url]

    John Bokma Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139