[PHP] function 3

Source: Internet
Author: User

// Obtain the current Script URL
Copy codeThe Code is as follows:
Function get_php_url (){
If (! Empty ($ _ server ["REQUEST_URI"]) {
$ ScriptName = $ _ SERVER ["REQUEST_URI"];
$ Nowurl = $ scriptName;
} Else {
$ ScriptName = $ _ SERVER ["PHP_SELF"];
If (empty ($ _ SERVER ["QUERY_STRING"]) $ nowurl = $ scriptName;
Else $ nowurl = $ scriptName ."? ". $ _ SERVER [" QUERY_STRING "];
}
Return $ nowurl;
}

// Convert the fullwidth number into a halfwidth number
Copy codeThe Code is as follows:
Function GetAlabNum ($ fnum ){
$ Nums = array ("0", "1", "2", "3", "4", "5", "6", "7 ", "8", "9 ");
$ Fnums = "0123456789 ";
For ($ I = 0; $ I <= 9; $ I ++) $ fnum = str_replace ($ nums [$ I], $ fnums [$ I], $ fnum );
$ Fnum = ereg_replace ("[^ 0-9 \.] | ^ 0 {1,}", "", $ fnum );
If ($ fnum = "") $ fnum = 0;
Return $ fnum;
}

// Remove HTML tags
Copy codeThe Code is as follows:
Function Text2Html ($ txt ){
$ Txt = str_replace ("", "", $ txt );
$ Txt = str_replace ("<", "<", $ txt );
$ Txt = str_replace (">", ">", $ txt );
$ Txt = preg_replace ("/[\ r \ n] {1,}/isU ","
\ R \ n ", $ txt );
Return $ txt;
}

// Clear the HTML Tag
Copy codeThe Code is as follows:

Function ClearHtml ($ str ){
$ Str = str_replace ('<', '<', $ str );
$ Str = str_replace ('>', '>', $ str );
Return $ str;
}

// Convert relative paths to absolute paths
Copy codeThe Code is as follows:

Function relative_to_absolute ($ content, $ feed_url ){
Preg_match ('/(http | https | ftp): \ //', $ feed_url, $ protocol );
$ Server_url = preg_replace ("/(http | https | ftp | news): \/\ //", "", $ feed_url );
$ Server_url = preg_replace ("// \/. */", "", $ server_url );

If ($ server_url = ''){
Return $ content;
}

If (isset ($ protocol [0]) {
$ New_content = preg_replace ('/href = "\ //', 'href =" '. $ protocol [0]. $ server_url.'/', $ content );
$ New_content = preg_replace ('/src = "\ //', 'src =" '. $ protocol [0]. $ server_url.'/', $ new_content );
} Else {
$ New_content = $ content;
}
Return $ new_content;
}

// Get all links
Copy codeThe Code is as follows:
Function get_all_url ($ code ){
Preg_match_all ('/<a \ s + href = ["| \']? ([^> "\ '] +) [" | \']? \ S * [^>] *> ([^>] +) <\/a>/I ', $ code, $ arr );
Return array ('name' => $ arr [2], 'url' => $ arr [1]);
}

// Convert each line of the HTML table into an array in CSV format
Copy codeThe Code is as follows:
Function get_tr_array ($ table ){
$ Table = preg_replace ("'<td [^>] *?> 'Si ", '"', $ table );
$ Table = str_replace ("</td>", '",', $ table );
$ Table = str_replace ("</tr>", "{tr}", $ table );
Function get_tr_array ($ table ){
$ Table = preg_replace ("'<td [^>] *?> 'Si ", '"', $ table );
$ Table = str_replace ("</td>", '",', $ table );
$ Table = str_replace ("</tr>", "{tr}", $ table );
// Remove the HTML Tag
$ Table = preg_replace ("'<[\/\!] *? [^ <>] *?> 'Si "," ", $ table );
// Remove the white space characters
$ Table = preg_replace ("'([\ r \ n]) [\ s] +'", "", $ table );
$ Table = str_replace ("", "", $ table );
$ Table = str_replace ("", "", $ table );

$ Table = explode (", {tr}", $ table );
Array_pop ($ table );
Return $ table;
}

// Convert each row and column of an HTML table into an array to collect table data
Copy codeThe Code is as follows:
Function get_td_array ($ table ){
$ Table = preg_replace ("'<table [^>] *?> 'Si "," ", $ table );
$ Table = preg_replace ("'<tr [^>] *?> 'Si "," ", $ table );
$ Table = preg_replace ("'<td [^>] *?> 'Si "," ", $ table );
$ Table = str_replace ("</tr>", "{tr}", $ table );
$ Table = str_replace ("</td>", "{td}", $ table );
// Remove the HTML Tag
$ Table = preg_replace ("'<[\/\!] *? [^ <>] *?> 'Si "," ", $ table );
// Remove the white space characters
$ Table = preg_replace ("'([\ r \ n]) [\ s] +'", "", $ table );
$ Table = str_replace ("", "", $ table );
$ Table = str_replace ("", "", $ table );

$ Table = explode ('{tr}', $ table );
Array_pop ($ table );
Foreach ($ table as $ key => $ tr ){
$ Td = explode ('{td}', $ tr );
Array_pop ($ td );
$ Td_array [] = $ td;
}
Return $ td_array;
}

// Return all words in the string $ distinct = true to remove duplicates
Copy codeThe Code is as follows:
Function split_en_str ($ str, $ distinct = true ){
Preg_match_all ('/([a-zA-Z] +)/', $ str, $ match );
If ($ distinct = true ){
$ Match [1] = array_unique ($ match [1]);
}
Sort ($ match [1]);
Return $ match [1];
}

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.