Thieves, collection procedures commonly used functions _ Thieves/Collection

Source: Internet
Author: User
<script language= "javascript" runat= "Server" >
Connecting to a database
function Connopen (DATABASECONNECTSTR) {
var conn = Server.CreateObject ("ADODB.") Connection ");
Conn. Open (DATABASECONNECTSTR);
Return conn;
}
Use the ADODB.stream object to read text files in a specified format
function Readfromtextfile (fileurl,charset) {
var str;
var stm = Server.CreateObject ("ADODB.stream");
Stm. Type = 2;
Stm. Mode = 3;
Stm. Charset=charset;
Stm.open;
Stm. LoadFromFile (Server.MapPath (FILEURL));
str = stm. ReadText
Stm.close;
return str;
}
Use the ADODB.stream object to write to a text file in the specified format
function Writetotextfile (fileurl,str,charset) {
var stm = Server.CreateObject ("ADODB.stream");
Stm. Type = 2;
Stm. Mode = 3;
Stm. Charset = Charset;
Stm.open;
Stm. WRITETEXT (STR);
Stm. SaveToFile (Server.MapPath (FILEURL), 2);
Stm.flush;
Stm.close;
}
Use FSO to determine whether a file exists
function Isfileexist (FILEURL) {
var FSO = Server.CreateObject ("Scripting.FileSystemObject")
if (FSO). FileExists (Server.MapPath (FILEURL))) {
return true;
}else{
return false;
}
}
Use FSO to write files
function Catefile (files,fbody) {
var fs = Server.CreateObject ("Scripting.FileSystemObject");
var a = fs. CreateTextFile (Server.MapPath (files));
A.write (Fbody);
A.close ();
}
Get target page source code
function Gethttppage (URL) {
var http= server.createobject ("Microsoft.XMLHTTP");
Http.open ("Get", url,false);
Http.send ();
if (http.readystate!==4) {return false;}
Return (BYTESTOBSTR (http.responsebody, "GB2312"));
}
Coding
function Bytestobstr (body,cset) {
var objstream = Server.CreateObject ("ADODB.stream");
Objstream. Type = 1;
Objstream. Mode = 3;
Objstream. Open ();
Objstream. Write = body;
Objstream. Position = 0;
Objstream. Type = 2;
Objstream. Charset = Cset;
Return (objstream. ReadText);
Objstream. Close ();
}
Get full Connection Address
function Getcompleteurl (sources_url,get_url) {
if (Get_url.indexof ("http://")!=-1) return get_url;
var completeurl= "";
var Sources_url_arr = Sources_url.split ("/");
var Get_url_arr = Get_url.split (".. /");
for (Var i=0;i<sources_url_arr.length-get_url_arr.length;i++) {
Completeurl + = Sources_url_arr[i] + "/";
}
Completeurl + = get_url_arr[get_url_arr.length-1];
return completeurl;
}
</script>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.