search engine help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • silmana
    New Member
    • Aug 2007
    • 19

    search engine help

    Hi i have this script that i want to use as php or html but i cant find the problem, could anyone solve the problem, i dont know why i cannot use it in php or html file

    // OBS! Några saker måste justeras för att skriptet skall fungera
    // 1) Du måste ange antal webbsidor som skall genomsökas
    // 2) Du måste lista dessa webbsidor
    // 3) Du måste justera variabeln mode (1= visa title, 2=visa länkar,
    // 3 = visa båda)
    //
    // Antal webbsidor som skall genomsökas. Ändra nedan i
    // variabeln nrOfPages
    //
    var nrOfPages=12;
    var mode=1
    var page=new Array(nrOfPages );

    //
    //
    // Lista webbsidorna här nedan som skall genomsökas.
    // Ange fullständig sökväg inkl. http://
    //
    page[0]='http://www.htmlsidan.s e';
    page[1]='http://www.htmlsidan.s e/?visa=artiklar' ;
    page[2]='http://www.htmlsidan.s e/?visa=skriptark iv';
    page[3]='http://www.htmlsidan.s e/?visa=designer' ;
    page[4]='http://www.htmlsidan.s e/?visa=webb';
    page[5]='http://www.htmlsidan.s e/?visa=service';
    page[6]='http://www.htmlsidan.s e/demo/ajax_sok_05.htm l';
    page[7]='http://www.htmlsidan.s e/?visa=tipsotrix ';
    page[8]='http://www.htmlsidan.s e/?visa=links';
    page[9]='http://www.htmlsidan.s e/?visa=topp_def' ;
    page[10]='http://www.htmlsidan.s e/?visa=fm_rules' ;
    page[11]='http://www.htmlsidan.s e/?visa=other_stu ff';
    //
    // Här nedan behöver du inte ändra någonting.
    //
    //
    var pageNr=0;
    var searchWord="";
    var result="";
    var ingetHittat=0;
    var nav=navigator.u serAgent.toLowe rCase();
    var title="";


    function search(word)
    {
    result="";
    pageNr=0;
    ingetHittat=0;
    result=result+" <b>Söker efter ""+word+"" ...</b><br/>";
    setText("search _result",result );
    searchPages(wor d);
    }

    function searchPages(wor d)
    {
    searchWord=word ;
    var httpRequest = getHttpRequest( );
    httpRequest.onr eadystatechange = function()
    {
    handleRequest(h ttpRequest);
    };

    httpRequest.ope n('GET', page[pageNr], true);
    httpRequest.sen d(null);
    }


    function handleRequest(h andle)
    {
    var text="";

    if (handle.readySt ate != 4)
    {
    return;
    }

    if (handle.status && (handle.status == 404) || (handle.status == 2))
    {
    alert('Webbsida eller fil saknas '+page[pageNr]);
    return;
    }

    if (handle.status && handle.status != 200)
    {
    alert('Felkod ' + handle.status );
    return;
    }

    text= handle.response Text;

    text=text.repla ce(/(\n)/g,"***");
    text=text.repla ce(/(\n)/g,"");

    matches=text.ma tch(/(<title.*?</title>)/gi);
    title=matches[0];
    title=title.rep lace(/(<.*?>)/gi,"");

    text=text.repla ce(/(<style*?</style)/gi,"");
    text=text.repla ce(/(<script.*?</script>)/gi,"");
    text=text.repla ce(/(<title.*?</title>)/gi,"");
    text=text.repla ce(/(<noframes.*?</noframes>)/gi,"");
    text=text.repla ce(/(&.*?;)/gi,"");
    text=text.repla ce(/(<.*?>)/gi,"");
    text=text.repla ce(/(***)/g,"\n");


    text=text.toLow erCase();

    if (text.match(sea rchWord.toLower Case())!=null)
    {
    if (mode==3)
    {
    title=title+" "+page[pageNr];
    }
    if (mode==2)
    {
    title=page[pageNr];
    }
    result=result+" » <a href=""+page[pageNr]+"">"+title+ "</a><br/>";

    setText("search _result",result );
    ingetHittat=1;
    }

    if (++pageNr<nrOfP ages)
    {
    searchPages(sea rchWord);
    }
    else
    {
    if (ingetHittat==0 )
    {
    result=result+" hittade ingenting";
    setText("search _result",result );
    }
    }
    }


    function getHttpRequest( )
    {
    var handle = false;

    if (window.XMLHttp Request)
    {
    handle = new XMLHttpRequest( );
    if(handle.overr ideMimeType) // Mozilla/Safari/IE7+
    {
    handle.override MimeType('text/xml; charset=iso-8859-1');
    }
    }
    else
    if (window.ActiveX Object)
    {
    try
    {
    handle = new ActiveXObject(" Msxml2.XMLHTTP" );
    }
    catch (e)
    {
    try
    {
    handle = new ActiveXObject(" Microsoft.XMLHT TP");
    }
    catch (e) {}
    }
    }

    if (!handle)
    {
    return false;
    }

    return handle;
    }

    function setText(namn,tx t)
    {
    if (document.all)
    {
    document.all[namn].innerHTML=txt;
    }
    else if (document.layer s)
    {
    document[namn].document.open( );
    document[namn].document.write (txt);
    document[namn].document.close ();
    }
    else if (document.getEl ementById)
    {
    document.getEle mentById(namn). innerHTML=txt;
    }
    }
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    That's javascript, mate.
    I suggest you try reading the posting guidelines before you post another load of unstyled code.

    Regards, markus.

    Comment

    • silmana
      New Member
      • Aug 2007
      • 19

      #3
      Originally posted by markusn00b
      That's javascript, mate.
      I suggest you try reading the posting guidelines before you post another load of unstyled code.

      Regards, markus.
      i know its javascript but can i make it to php

      Comment

      • Markus
        Recognized Expert Expert
        • Jun 2007
        • 6092

        #4
        Originally posted by silmana
        i know its javascript but can i make it to php
        I, aswell as everyone else, have no idea what the script does. Therefore, i cannot possibly attempt to convert it to php.

        Maybe some explanation of what it does would help? Maybe.

        Regards.

        9 times out of 10 javascript cannot be converted TO php because javascript is NOTHING like php. They work under different environments.

        Comment

        • silmana
          New Member
          • Aug 2007
          • 19

          #5
          Originally posted by markusn00b
          I, aswell as everyone else, have no idea what the script does. Therefore, i cannot possibly attempt to convert it to php.

          Maybe some explanation of what it does would help? Maybe.

          Regards.

          9 times out of 10 javascript cannot be converted TO php because javascript is NOTHING like php. They work under different environments.

          hi again, this is a script for a search engine and the website that i took from said that i could make it to php by using this line or something header('text/html; charset=iso-8859-1'); could you check it out, mix little with the script and see if you could make it php?

          Thanks

          Comment

          • satas
            New Member
            • Nov 2007
            • 82

            #6
            Originally posted by silmana
            hi again, this is a script for a search engine and the website that i took from said that i could make it to php by using this line or something header('text/html; charset=iso-8859-1'); could you check it out, mix little with the script and see if you could make it php?

            Thanks
            It seems that you have to write backend for this AJAX-based tool.
            Good luck :)

            Comment

            Working...