how to filter/search/replace on a page

Discussion in 'HTML' started by mentalguy2004, Aug 12, 2004.

  1. Hi,

    I want to be able to fetch a 3rd party page to my server, search for
    multiple (different) specific text strings and replace them with my own,
    then output the changed page to my own server. Is there anything out there
    that can help me do this without having to write lots of code? Something
    like those "joke" filters where you paste a URL into it and it loads that
    page with silly words & "graffiti" on it although I only need to replace
    specific words with other specific words, nothing random.

    Currently, I'm having to download the 3rd party page source, paste it into a
    search& replace Windows prog with several filters, copy the result into an
    HTML page and upload it. I was looking for something that could do the job
    *slightly* quicker.... my server can use PHP, ASP, CGI & HTML.

    Thanks.
     
    mentalguy2004, Aug 12, 2004
    #1
    1. Advertising

  2. *mentalguy2004* wrote:
    > I want to be able to fetch a 3rd party page to my server, search for
    > multiple (different) specific text strings and replace them with my
    > own, then output the changed page to my own server. Is there anything
    > out there that can help me do this without having to write lots of
    > code? Something like those "joke" filters where you paste a URL into
    > it and it loads that page with silly words & "graffiti" on it
    > although I only need to replace specific words with other specific
    > words, nothing random.
    >
    > Currently, I'm having to download the 3rd party page source, paste it
    > into a search& replace Windows prog with several filters, copy the
    > result into an HTML page and upload it. I was looking for something
    > that could do the job *slightly* quicker.... my server can use PHP,
    > ASP, CGI & HTML.


    An ASP/IIS solution would be to use 'ServerXMLHTTP' to fetch the
    requested document and then use regular expressions on the returned
    'responseText' to do your replacement. I suggest that you do this in a
    separate back-end process (ie. not when a user makes a request for your
    version of the page) and cache the result if the fetch was successful.
    End-users are then piped this cached version (perhaps via
    Server.Execute) when they make a request for the page.

    Additionally if the source server supports 'Etag' and 'last-modified'
    headers you can use the 'If-Modified-Since' and 'If-None-Match' headers
    in your request to see if the document has changed since you last asked
    for it and so potentially save on server resources.
    --
    Andrew Urquhart
    - FAQ: http://www.html-faq.com
    - Archive: http://www.google.com/groups?q=alt.html
    - Contact me: http://andrewu.co.uk/contact/
    - This post is probably time-stamped +1 hour - blame my ISP (NTL)
     
    Andrew Urquhart, Aug 12, 2004
    #2
    1. Advertising

  3. mentalguy2004

    Toby Inkster Guest

    mentalguy2004 wrote:

    > I want to be able to fetch a 3rd party page to my server, search for
    > multiple (different) specific text strings and replace them with my own,
    > then output the changed page to my own server.


    In PHP something like this ought to work:

    <?php
    $content = file_get_contents("http://example.org/somefile.html");
    $newcontent = preg_replace('/foo/', 'bar', $content);
    print $newcontent;
    ?>

    --
    Toby A Inkster BSc (Hons) ARCS
    Contact Me ~ http://tobyinkster.co.uk/contact
     
    Toby Inkster, Aug 12, 2004
    #3
  4. mentalguy2004

    Toby Inkster Guest

    mentalguy2004 wrote:

    > OK, I've got that working, but I can't for the life of me get it to process
    > multiple replacements at the same time.


    <?php
    $content = file_get_contents("http://example.org/somefile.html");
    $newcontent = preg_replace('/Thomas/', 'Tom', $content);
    $newcontent = preg_replace('/Richard/', 'Dick', $newcontent);
    $newcontent = preg_replace('/Harold/', 'Harry', $newcontent);
    print $newcontent;
    ?>

    --
    Toby A Inkster BSc (Hons) ARCS
    Contact Me ~ http://tobyinkster.co.uk/contact
     
    Toby Inkster, Aug 12, 2004
    #4
  5. OK, I've got that working, but I can't for the life of me get it to process
    multiple replacements at the same time.

    I've tried most ways, but am having to put a different version of the line
    $newcontent = preg_replace('/foo/', 'bar', $content);

    for every different string, and it's ignoring all instances of each. The
    original page is fetched and displayed fine, but there are no changes to it.

    How can I insert the different strings to search for and replace into this
    bit of code?

    thanks for your help~!

    "Toby Inkster" <> wrote in message
    news:p...
    > mentalguy2004 wrote:
    >
    > > I want to be able to fetch a 3rd party page to my server, search for
    > > multiple (different) specific text strings and replace them with my own,
    > > then output the changed page to my own server.

    >
    > In PHP something like this ought to work:
    >
    > <?php
    > $content = file_get_contents("http://example.org/somefile.html");
    > $newcontent = preg_replace('/foo/', 'bar', $content);
    > print $newcontent;
    > ?>
    >
    > --
    > Toby A Inkster BSc (Hons) ARCS
    > Contact Me ~ http://tobyinkster.co.uk/contact
    >
     
    mentalguy2004, Aug 12, 2004
    #5
  6. mentalguy2004

    Toby Inkster Guest

    mentalguy2004 wrote:

    > I've got it working perfectly, thanks! Just one final question, how do I get
    > the "Tom" "Dick" or "Harry" to be a different colour to the rest of the
    > text?


    preg_replace('/Thomas/','<strong style="color:green">Tom</strong>',$content);

    --
    Toby A Inkster BSc (Hons) ARCS
    Contact Me ~ http://tobyinkster.co.uk/contact
     
    Toby Inkster, Aug 12, 2004
    #6
  7. I've got it working perfectly, thanks! Just one final question, how do I get
    the "Tom" "Dick" or "Harry" to be a different colour to the rest of the
    text? I need to highlight them, but I don't know how to do this. Thanks a
    lot :)


    "Toby Inkster" <> wrote in message
    news:p...
    > mentalguy2004 wrote:
    >
    > > OK, I've got that working, but I can't for the life of me get it to

    process
    > > multiple replacements at the same time.

    >
    > <?php
    > $content = file_get_contents("http://example.org/somefile.html");
    > $newcontent = preg_replace('/Thomas/', 'Tom', $content);
    > $newcontent = preg_replace('/Richard/', 'Dick', $newcontent);
    > $newcontent = preg_replace('/Harold/', 'Harry', $newcontent);
    > print $newcontent;
    > ?>
    >
    > --
    > Toby A Inkster BSc (Hons) ARCS
    > Contact Me ~ http://tobyinkster.co.uk/contact
    >
     
    mentalguy2004, Aug 12, 2004
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. jeffreycope

    Search / Filter Records

    jeffreycope, Jul 25, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    397
    jeffreycope
    Jul 25, 2003
  2. =?Utf-8?B?QUo=?=

    Search Filter!

    =?Utf-8?B?QUo=?=, Oct 31, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    499
    =?Utf-8?B?RWx0b24gVw==?=
    Nov 1, 2005
  3. thebison

    Search button to filter a DataGrid

    thebison, Mar 5, 2006, in forum: ASP .Net
    Replies:
    10
    Views:
    14,818
    deedivs
    Oct 25, 2006
  4. zax75
    Replies:
    1
    Views:
    1,123
  5. Abby Lee
    Replies:
    5
    Views:
    443
    Abby Lee
    Aug 2, 2004
Loading...

Share This Page