Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Dec 2002
    earth, usa, az
    Thanked 0 Times in 0 Posts

    Question Search form post to new page's iframe?

    Ok try to bear with me here...

    I have a site where 80% of it is being fed in through iframes from another page (yes mine but i wanted a custom design for a vendor supplied product search site).

    The categories on the left nav opens a new dedicated page with an iframe in it containing the link from my vendor site so basically a looong search query URL like
    Now I want to be able to perform a search from any page in a search box i'm putting into the header.

    From any page, I want to have the search box results open in a new page like /search/ and have the results post in that page's iframe.

    Is this possible? If so how do I accomplish this with php

    Currently I have an invisible iframe named 'keywordsearch' on every single page with no source and if the search box is filled out it opens the iframe with z-index:100 over the current page's content... icky I know but frames suck.

    Thanks much for your help.

  • #2
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    the U.S. of freakin' A.
    Thanked 158 Times in 149 Posts
    In order to do what you want to do, I think you;d literally need to open up every page that you want searchable on your vendor's site, and search each remote file for the search keyword(s). When a match was found, you would need to record the file name that the match was found in, and probably capture some of the context text surrounding the keyword match. Then take all of this info and build your pseudo-iframe (I say pseudo, because this iframe will link to content on your server) on your search page. In fact you don;t even need a real iframe here; you could use some CSS to simulate an iframe. (that way you only need one file, not two). Finally, Use the information you compiled earlier to build the links in your search results (inside the pseudo-iframe on your search page).

    So anyway, my general approach for this would be to:

    1) Your search box on every page of your site would send POST information to your search results page, let's call it search.php.

    2) on search.php, create an array that contains all of the remote files that you want to search.

    3) Loop through your array, and use file_get_contents() on each URL to get that URL's contents, search each page's contents with some regex, and fill an array with the results:

    PHP Code:
    $file_array = array('my_home.php' => 'index.php','my_products.php' => 'products.php','my_services.php' => 'services.php');  // where the keys are your pages, and the values are the vendor's pages on your corresponding "key" pages
    $pattern '/(.{0,100}?)('.preg_quote($_POST['search_phrase'],'/').')(.{0,100})/i)';
    results = array();

    foreach (
    $file_array as $key => $val)
    $contents file_get_contents("http://www.vendorSite.com/".$val);
    $contents strip_tags($contents);
        if (!empty(
            foreach (
    matches[2] as $k => $v)
    $results[x]['blurb'] = "..." $matches[1][$k] . '<font color="#FF0000"><b>' $matches[2][$k] . "</b></font>" $matches[3][$k] . "...";       
    $results[x]['file'] = $key;    

    4) Then you iterate through the $results array inside your pseudo iframe (I think creating a CSS iframe look-alike is your best bet), and display the results links however you want (the following is just a simple example):

    PHP Code:
    foreach (
    $results as $key => $val)
    "<p>$y) <a href='http://www.yourSite.com/".$results[$key]['file']."'>".$results[$key]['file']."</a></p>";    
    "<p>".$results[$key]['blurb']."</p><br />";

    I didn;t test any of this -- just trying to give you a direction to run with. Good luck!
    Last edited by chump2877; 12-02-2006 at 05:21 AM.
    Regards, R.J.


    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :-)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!
    ♪♪ …Need Web Hosting For My YouTube-To-Mp3 Conversion Software? Check Here !!… ♪♪


    Posting Permissions

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