Loading ...
Sorry, an error occurred while loading the content.

[PBML] Search and replacing text in a file

Expand Messages
  • webprogramming
    I need to search and replace a certain word in a text file from a webform submission. The user would enter a word (in this case a domain name) in an input box
    Message 1 of 2 , Oct 8, 1998
    View Source
    • 0 Attachment
      I need to search and replace a certain word in a text file from a webform
      submission. The user would enter a word (in this case a domain name) in an
      input box on a webform, and submit; the script would grab the text file ,
      search for the word "template", and replace it with the domain name entered
      by the user, save the file with a new name (domain_name.db) and close it. I
      think I can do this with a while (<>) diamond operator , and a substitution
      command. What would be the easiest way to do this.

      Thanks in advance
      Roland Gregory
      Executive Producer
      RadiowaveInternet
      ______________________________________________________________________
      For easy online travel reservations, go to Internet Travel Network:
      http://www.itn.net

      Subscribe, unsubscribe, opt for a daily digest, or start a new e-group
      at http://www.eGroups.com -- Free Web-based e-mail groups.
    • Jeff Boes
      On Thu, 08 Oct 1998 14:02:29 -0700, webprogramming ... Something like this: use CGI :standard ; $word = param( word );
      Message 2 of 2 , Oct 8, 1998
      View Source
      • 0 Attachment
        On Thu, 08 Oct 1998 14:02:29 -0700, webprogramming <info@...>
        wrote:

        >I need to search and replace a certain word in a text file from a webform
        >submission. The user would enter a word (in this case a domain name) in an
        >input box on a webform, and submit; the script would grab the text file ,
        >search for the word "template", and replace it with the domain name entered
        >by the user, save the file with a new name (domain_name.db) and close it. I
        >think I can do this with a while (<>) diamond operator , and a substitution
        >command. What would be the easiest way to do this.

        Something like this:

        use CGI ':standard';
        $word = param('word');
        open(FOO,'<file.ext') || die;
        open(BAR,'>newfile.ext') || die;
        while (<FOO>)
        {
        s/template/$foo/g;
        print $_;
        }

        This is just a skeleton, without much error checking or chrome, but it should
        get you started.


        --
        Jeffery Boes
        jboes@... UIN 3394914 (ICQ: www.mirabilis.com)
        DBA/Developer/Web Engineer for hire
        "Sucking up bandwidth since 1994."
        ______________________________________________________________________
        For easy online travel reservations, go to Internet Travel Network:
        http://www.itn.net

        Subscribe, unsubscribe, opt for a daily digest, or start a new e-group
        at http://www.eGroups.com -- Free Web-based e-mail groups.
      Your message has been successfully submitted and would be delivered to recipients shortly.