Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Printing information

Status
Not open for further replies.

sulfericacid

Programmer
Aug 15, 2001
244
US
I am designing an extensive meta tag generator. I know how to make it email it to people and print it on the screen...

I saw it once where the script called onto a file where ^results^ was in the source code. Wherever that code would be, that is where the information from that script would print.

How can I make all my information look for one word, IE. ^result^ so all I need to do is put that into my HTML document somewhere and that is where it will load. If I put that inside of a table, it will load inside of a table.

Anyone know what I mean? Anyone know how?

I have too many tables on my site now and I do not want to have to print all those tables in the script, all I want is for it to search for a .html file and have it look for ^results^ and have it post there.
 
All you need to do is open the html file, read it in, and do a search & replace on each line. What language are you using. I can post a perl routine to do what you want.
Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Here is an example of a general flow.....
Code:
#!/usr/local/bin/perl

open(INPUTFILE,&quot;<file_to_modify.html&quot;) or die &quot;Failed to open input file, $!\n&quot;;
while (<INPUTFILE>) { $buffer .= $_; }
close INPUTFILE;

$string = 'some text to insert into the file every place there is a tag';
$tag = '<swap_text_here>';

# use the regex replace syntax to replace $tag with $string.
$buffer =~ s/$tag/$string/gs;

open(OUTPUTFILE,&quot;>file_name_to_write_to&quot;) or die &quot;Can't open file, $!\n&quot;;
print OUTPUTFILE &quot;$buffer&quot;;
close OUTPUTFILE;

HTH




keep the rudder amid ship and beware the odd typo
 
Thanks for your reply. I think I understand what you are saying, but I am quite new at this. I am not sure how to open an HTML file much less read and search it, lol. Could you explain it more or show me a place that shows what you are talking about?

Oh, I am using perl :)

Thanks millions!

Aaron
 
One more question: do you want to permanently replace the tag with generated text, or do you want to do it every time the page is displayed, so if you change the generated text the page will automatically display the new text? One way requires simply changing and replacing the html files, the other way requires that the html files are read, processed, and printed by the cgi program, rather than being simply downloaded by the browser. Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Hi again!

I am not too clear, but I will try and explain.

This is just a meta tag script where once they put in their info and click submit, it will load my html page and look for the word ^REPLACE^ and print all information the user added.

If they want to change the output, they would have to do the meta tags all over and that would make the script have different results.

BTW, it isn't just text that is to be printed when ^REPLACE^ is found. It is a table too, does that conflict anything?

Thanks again!

Aaron
 
What is going into the ^REPLACE^ section isn't important. You can put just about anything you want in it, just so it fits into the overall html.

It sounds from what you said that you want the script to process and display the pages each time they are viewed, rather than having them static. That means that links to the pages have to be in the form href=&quot;/cgi-bin/replacer.pl?/path/pagename.html&quot;. Is that what you want?

There is another alternative to doing this with a perl program too. You can put the text you want to include in a separate file and use server side includes to include that text into another file. That's probably easier and more efficient than serving the pages with a cgi program. Instead of ^REPLACE^ in the html you would have &quot;<!-- #include file=&quot;/filename.txt&quot; -->&quot; (I think that's the correct syntax). You might also have to rename the pages to .shtml instead of .html.

Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
goBoating, above, gave me some codes which I tried to mess with. Do yout hink it would work?

<code>
open (INPUTFILE,”<spydertagcomplete.html”) or die “Failed to open input file, $!\n;
while (<INPUTFILE>) { $buffer .=$_; }
close INPUTFILE;

# $tags is all the data they input
$string .=$tags;
$tag = ‘^results^’;

# use the regex replace syntax to replace $tag with $string.
$buffer =~ s/$tag/$string/gs;

open(OUTPUTFILE,”>spydertagcomplete.html”) or die “Can’t open file, $!\n”;
print OUTPUTFILE “$buffer”;
close OUTPUTFILE;
</code>

But as for your last method, using #include... All i would have to do is have my $tags (where all the meta tags are stored) print to that file and use those codes to open it on that page? That would still allow all the HTML to be stored into that file and still be read as html, right? I think that way seems to be a lot easier!

Sorry, I am new at this and I just keep on running into more and more problems :(

Thanks billions for your help!
 
Yes, using the #include you would print your tags out to a text file, and just include that file wherever you need it. The server handles the include for you. If you change the text file, the changes are included the next time someone loads the page(s) it's included in. For this type of application I think it's probably best method to use. The method goBoating gave would work, but the changes are permanent: the ^REPLACE^ tag is permanently replaced, so you can't change the included text and do it again. The method I mentioned (serving the pages with a cgi program) is best when the data you want to include on the page changes constantly, or based on user input.
Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top