Pages

Monday, November 22, 2010

Get search key word from the referrer url.

 C#.Net

This is a very simple way to do actually. Web developers are very much familiar to work with the referrer url. The HTTP_REFERER server variable return the referrer url. In this tips I will show how easily we can get the search key word from the referrer url.



public string GetSearchKeyWords(string strQuery)
{
string result = "";
string pattern = "\b\w*p=(?!u)\w*\b|\b\w*q=(?!u)\w*\b|\b\w*qs=(?!u)\w*\b" + "|\b\w*encquery=(?!u)\w*\b|\b\w*k=(?!u)\w*\b\b\w*qt=(?!u)\w*\b" + "|\b\w*query=(?!u)\w*\b|\b\w*rdata=(?!u)\w*\b|\b\w*search_word=(?!u)\w*\b" + "|\b\w*szukaj|terms=(?!u)\w*\b\b\w*text=(?!u)\w*\b|\b\w*wd=(?!u)\w*\b|\b\w*words=(?!u)\w*\b";

foreach
(Match m in Regex.Matches(strQuery, pattern))
{
// get the matched string
string x = m.ToString();
x = x.Substring(1, x.Length - 1);
// collect all text result += x;
}
return result.Replace("=", "");
}



Input: http://www.google.com/url?sa=t&source=web&cd=7&ved=0CEQQFjAG&url=http%3A%2F%2Fwww.example.com%2F&rct=j&q=developersproject.com=uSLVTMm0JYXNhAewqbzjBA&usg=AFQjCNFtfSFIuj4fxnl8bD_bR2NgzDePGw&cad=rja


Output: developersproject.com

No comments: