Common functions in PHP collection programs-PHP Tutorial

Source: Internet
Author: User
Common functions in PHP collection programs. Copy the code as follows: get the current script URL functionget_php_url () {if (! Empty ($ _ SERVER ["REQUEST_URI"]) {$ scriptName $ _ SERVER ["REQUEST_URI"]; $ nowurl $ SC The code is as follows:


// Obtain the current script URL
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
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
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
Function ClearHtml ($ str)
{
$ Str = str_replace ('<', '<', $ str );
$ Str = str_replace ('>', '>', $ str );
Return $ str;
}

// Convert relative paths to absolute paths
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
Function get_all_url ($ code ){
Preg_match_all ('/"\'] +) [" | \ ']? \ S * [^>] *> ([^>] +) <\/a>/I ', $ code, $ arr );
Return array ('name' => $ arr [2], 'URL' => $ arr [1]);
}

// Obtain the content in the specified tag
Function get_tag_data ($ str, $ start, $ end)
{
If ($ start = "| $ end = ")
{
Return;
}
$ Str = explode ($ start, $ str );
$ Str = explode ($ end, $ str [1]);
Return $ str [0];
}

// Convert each line of the HTML table into an array in CSV format
Function get_tr_array ($ table)
{
$ Table = preg_replace ("' ] *?> 'Si ", '"', $ table );
$ Table = str_replace ("", '",', $ Table );
$ Table = str_replace (""," {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
Function get_td_array ($ table)
{
$ Table = preg_replace ("' ] *?> 'Si ",", $ table );
$ Table = preg_replace ("' ] *?> 'Si ",", $ table );
$ Table = preg_replace ("' ] *?> 'Si ",", $ table );
$ Table = str_replace (""," {Tr} ", $ table );
$ Table = str_replace (""," {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
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];
}

The http://www.bkjia.com/PHPjc/320956.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/320956.htmlTechArticle code is as follows: // get the current script URL function get_php_url () {if (! Empty ($ _ SERVER ["REQUEST_URI"]) {$ scriptName = $ _ SERVER ["REQUEST_URI"]; $ nowurl = $ SC...

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.