Welcome to Dream.In.Code
Getting Help is Easy!

Join 136,326 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 2,820 people online right now. Registration is fast and FREE... Join Now!




Changing color in cgi

 
Reply to this topicStart new topic

Changing color in cgi

rodstol
18 Aug, 2008 - 12:26 PM
Post #1

New D.I.C Head
*

Joined: 3 Apr, 2008
Posts: 39

I installed this search script, but I'm needing it's results text to show up in a different color.
However, I'm not seeing anything that resembles a css like I expected.

How would you change the results color? I'm assuming you can wrap the results in a div, but I'm not understanding where or how a div tag relates in a cgi script.


CODE
#!/usr/bin/perl

print "Content-type:text/html\n\n";

$thisScript=$ENV{'SCRIPT_NAME'};
$data = $ENV{'SCRIPT_FILENAME'};
$data=~s/(.*)\/.*/$1/;
$top="$data/Top.html";
$bottom="$data/Bottom.html";
$data="$data/data/index.dat";


$query = $ENV{'QUERY_STRING'};
@pairs = split(/&/,$query);
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;
}


$searchwords=$FORM{'search'};
$searchwords=~s/[\|\\\/\!\@\#\$\%\^\&\*\(\)\[\]\{\}\;\:\'\"\+\=\-\_\?\.\,]//isg;

@terms=split(/\s+/,$searchwords);

open(FILE, "$data") or dieNice ("Can't open file: $data.<br>Please run archive.cgi script");

  $no=0;
  while ($line=<FILE>)
  {
     ($URL, $title, $keywords, $description) = split(/\|\|\|/, $line);
     $matches=0;
     foreach $word (@terms)
     {
       if (($keywords=~/$word/i) or ($title=~/$word/i)) {$matches++}
     }
     if ($matches)
     {
        $found{$URL}=$matches;
        $title{$URL}=$title;
        $description{$URL}=$description;
     }
  }
  while (scalar(%found))
  {
     $maxMatches=0;
     while (($URL,$matches)=each(%found))
     {
        if ($matches>$maxMatches)
        {
           $maxMatches=$matches;
           $maxURL=$URL;
        }
     }
     $results[$no]=$maxURL;
     $no++;
     delete $found{$maxURL};
  }

close(FILE);


open (HTML, $top);
@lines=<HTML>;
close (HTML);

foreach $line (@lines)
{
  print "$line";
}
#################################

print "<p>Found <b>".scalar(@results)."<\/b> matches for <b>$searchwords<\/b>.<\/p>";
if (@results) {
  for ($i=0; $i<@results; ++$i){
    $no=$i+1;
    print "$no. <a href=\"http\:\/\/$results[$i]\">$title{$results[$i]}<\/a> (http\:\/\/$results[$i])<br>\n";
    print "$description{$results[$i]}<br><br>\n";
  }
}
else {print "Your search has returned <b>no results<\/b>.<br><br>Please, try again.<br>\n"}
print "<\/td><\/tr>\n";


open (HTML, $bottom);
@lines=<HTML>;
close (HTML);

foreach $line (@lines)
{
  print "$line";
}
##########################
sub dieNice
{
print<<EndHTML9;
  <center><h2>An error has occured!</h2></center>
  <p>$_[0]</p>
  <p>If you have a problem, e-mail us with a short description of an error.</p>
  </body>
  </html>
EndHTML9
exit;
}
########### END SUBROUTINE#############

User is offlineProfile CardPM
+Quote Post

perfectly.insane
RE: Changing Color In Cgi
21 Aug, 2008 - 06:02 PM
Post #2

D.I.C Addict
Group Icon

Joined: 22 Mar, 2008
Posts: 558



Thanked: 46 times
Dream Kudos: 25
Expert In: C/C++

My Contributions
If you wish to change the formatting using CSS, you should use the span tag, with the class attribute. This is similar to a div, but it does not actually change the layout, but it simply applies the CSS class you give to the text. Really, you can just use your own tag if you really want to....

<style type="text/css">
result { color: #FFFFFF; }
</style>

...... later on .......

<result>Result 1</result>
<result>Result 2</result>


Or, you can use span:

<style type="text/css">
.result { color: #FFFFFF; }
</style>


.... later on ....

<span class="result">Result...</span>

User is offlineProfile CardPM
+Quote Post

KevinADC
RE: Changing Color In Cgi
21 Aug, 2008 - 10:43 PM
Post #3

D.I.C Head
Group Icon

Joined: 23 Jan, 2007
Posts: 214



Thanked: 3 times
Dream Kudos: 50
My Contributions
or:

<a style=\"color:red;\" src=\".......\"

This post has been edited by KevinADC: 21 Aug, 2008 - 10:45 PM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 07:46AM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month