Lost63 original php code that replaces content in batches
The code is as follows:
$ Path = $ DOCUMENT_ROOT;
$ Path = str_replace ("/", "\", $ path );
// Specify a folder
$ Path = $ path. "\ web \ study \\";
// Obtain all objects
$ S = explode ("\ n", trim ('DIR/B/o: gn $ path '));
// Obtain all HTML file names in the folder
$ Num = count ($ s );
For ($ I = 0; $ I <= $ num; $ I ++ ){
If (strpos ($ s [$ I], ". htm") = 0 ){
Unset ($ s [$ I]);
}
}
// Print_r ($ s );
// Batch processing webpage
Foreach ($ s as $ value ){
Editfile ("D :\\ MYOA \ webroot \ web \ study \". $ value );
Echo $ value. "updated!
";
}
// Editfile ("D :\\ MYOA \ webroot \ web \ study \ 0105_5.htm ");
Echo "the end ";
// Custom function: intercept the content between tags
Function get_body ($ start_str, $ end_str, $ content ){
$ Start_str_num = strlen ($ start_str );
$ End_str_num = strlen ($ end_str );
$ A = strpos ($ content, $ start_str) + $ start_str_num;
$ B = strpos ($ content, $ end_str)-strpos ($ content, $ start_str)-$ start_str_num;
Return substr ($ content, $ a, $ B );
}
// Edit the file
Function editfile ($ str ){
// $ Str = "D :\\ MYOA \ webroot \ web \ study \". $ str
// Obtain HTML content
$ File = @ fopen ($ str, "r ");
While (! Feof ($ file )){
$ Result. = fgets ($ file, 9999 );
}
Fclose ($ file );
// Replace content
$ Result = str_replace ("Old Wang's digital accessories store: Wang Po digital", "Lan Shi", $ result );
$ Result = str_replace ("photography online school", "back to the tutorial homepage", $ result );
$ Result = str_replace ('width = "407" ', 'width = "770"', $ result );
$ Result = str_replace ("http://shop1289309.taobao.com", "http://www.lansj.com", $ result );
$ Result = str_replace ("Old Wang uses pccity, joshwang, joshwanggg", "", $ result );
$ Result = str_replace ("QQ: 123709080 MSN: joshwanggg@hotmail.com", 'online Consulting: ', $ result );
$ Result = str_replace ('http: // www.zonline.com.cn </a>
', "", $ Result );
$ Result = str_replace ('http: // www.zonline.com.cn/photo/school/scgs/', "http://www.lansj.com/study/", $ result );
$ Result = str_replace ('http: // www.yimei.net/css/', "http://www.lansj.com/study/", $ result );
$ Result = str_replace ('http: // www.zonline.com.cn/photo/school/img/', "http://www.lansj.com/study/", $ result );
$ Result = str_replace ('http: // www.yimei.net/inc/', "http://www.lansj.com/study/", $ result );
$ Result = str_replace ('oak photography club ', 'Lan horizon photography BBS', $ result );
$ Result = str_replace ('http: // www.zonline.com.cn/photo/img/','http://www.lansj.com/study/', then result );
$ Result = str_replace ('
If you have any questions about digital equipment and accessories, you can send QQ: 123709080 inquiries, digital cameras and related accessories: Wang Po Digital
', "", $ Result );
$ Result = str_replace ("Untitled Document", substr (str_replace (chr (32), "", str_replace (chr (10), "", str_replace ("
"," ", Str_replace (chr (13)," ", get_body ('
','
', $ Result), 0, 28). "-Lan horizon photography", $ result );
$ Result = str_replace ("photography world", substr (str_replace (chr (32), "", str_replace (chr (10), "", str_replace ("
"," ", Str_replace (chr (13)," ", get_body ('', '', $ result), 0, 28 ). "-Lan horizon photography", $ result );
// Echo $ result;
// Update HTML
$ File = @ fopen ($ str, "w ");
Fwrite ($ file, $ result );
Fclose ($ file );
}
?>