PHP collection function)

Source: Internet
Author: User

// Obtain the current Script URLFunction 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 numberFunction 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 tagsFunction text2html ($ txt) {$ TXT = str_replace ("", ", $ txt); $ TXT = str_replace (" <"," & lt ;", $ txt); $ TXT = str_replace (">", "& gt;", $ txt); $ TXT = preg_replace ("/[\ r \ n] {1 ,} /ISU "," <br/> \ r \ n ", $ txt); return $ txt ;}

// Clear the HTML TagFunction clearhtml ($ Str) {$ STR = str_replace ('<', '& lt;', $ Str); $ STR = str_replace ('>', '& gt; ', $ Str); return $ STR ;}

// Convert relative paths to absolute pathsFunction 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 linksFunction get_all_url ($ code) {preg_match_all ('/<A \ s + href = ["| \']? ([^> "\ '] +) [" | \']? \ S * [^>] *> ([^>] +) <\/A>/I ', $ code, $ ARR ); return array ('name' => $ arr [2], 'url' => $ arr [1]);}

// Obtain the content in the specified tagFunction get_tag_data ($ STR, $ start, $ end) {if ($ start = "| $ end =") {return;} $ STR = explode ($ start, $ Str); $ STR = explode ($ end, $ STR [1]); return $ STR [0];}

// Convert each row of an HTML table to an array in CSV format. 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 blank character $ 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 dataFunction 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 blank character $ 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 duplicatesFunction 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.