By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,853 Members | 936 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,853 IT Pros & Developers. It's quick & easy.

search engine help

P: 19
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.se';
page[1]='http://www.htmlsidan.se/?visa=artiklar';
page[2]='http://www.htmlsidan.se/?visa=skriptarkiv';
page[3]='http://www.htmlsidan.se/?visa=designer';
page[4]='http://www.htmlsidan.se/?visa=webb';
page[5]='http://www.htmlsidan.se/?visa=service';
page[6]='http://www.htmlsidan.se/demo/ajax_sok_05.html';
page[7]='http://www.htmlsidan.se/?visa=tipsotrix';
page[8]='http://www.htmlsidan.se/?visa=links';
page[9]='http://www.htmlsidan.se/?visa=topp_def';
page[10]='http://www.htmlsidan.se/?visa=fm_rules';
page[11]='http://www.htmlsidan.se/?visa=other_stuff';
//
// Här nedan behöver du inte ändra någonting.
//
//
var pageNr=0;
var searchWord="";
var result="";
var ingetHittat=0;
var nav=navigator.userAgent.toLowerCase();
var title="";


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

function searchPages(word)
{
searchWord=word;
var httpRequest = getHttpRequest();
httpRequest.onreadystatechange = function()
{
handleRequest(httpRequest);
};

httpRequest.open('GET', page[pageNr], true);
httpRequest.send(null);
}


function handleRequest(handle)
{
var text="";

if (handle.readyState != 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.responseText;

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

matches=text.match(/(<title.*?</title>)/gi);
title=matches[0];
title=title.replace(/(<.*?>)/gi,"");

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


text=text.toLowerCase();

if (text.match(searchWord.toLowerCase())!=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<nrOfPages)
{
searchPages(searchWord);
}
else
{
if (ingetHittat==0)
{
result=result+"hittade ingenting";
setText("search_result",result);
}
}
}


function getHttpRequest()
{
var handle = false;

if (window.XMLHttpRequest)
{
handle = new XMLHttpRequest();
if(handle.overrideMimeType) // Mozilla/Safari/IE7+
{
handle.overrideMimeType('text/xml; charset=iso-8859-1');
}
}
else
if (window.ActiveXObject)
{
try
{
handle = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
handle = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e) {}
}
}

if (!handle)
{
return false;
}

return handle;
}

function setText(namn,txt)
{
if (document.all)
{
document.all[namn].innerHTML=txt;
}
else if (document.layers)
{
document[namn].document.open();
document[namn].document.write(txt);
document[namn].document.close();
}
else if (document.getElementById)
{
document.getElementById(namn).innerHTML=txt;
}
}
Mar 17 '08 #1
Share this Question
Share on Google+
5 Replies


Markus
Expert 5K+
P: 6,050
That's javascript, mate.
I suggest you try reading the posting guidelines before you post another load of unstyled code.

Regards, markus.
Mar 17 '08 #2

P: 19
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
Mar 17 '08 #3

Markus
Expert 5K+
P: 6,050
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.
Mar 17 '08 #4

P: 19
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
Mar 17 '08 #5

P: 82
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 :)
Mar 18 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.