How does php process files and extract content to generate files? Php file generation php
This is an original html file.
Untitled Document
This is a processed html file.
Untitled Document
Then extract the content fragments and generate the following three files,
Extract this part to generate head.html
Untitled Document
Extract this part to generate index.html
Extract this part to generate foot.html
Reply to discussion (solution)
$ S = <HTML
Untitled Document
HTML; preg_match_all ('/.*?
/Is ', $ s, $ r); print_r ($ r [0]);
Get
Array ([0] =>
Untitled Document
[1] =>
[2] =>
)
Write to file
$fn = array('head.html', ' index.html', 'foot.html');foreach($r[0] as $i=>$s) file_put_contents($fn[$i], $s);
$ S = <HTML
Untitled Document
HTML; $ ar = preg_split ("/(
\ S + | \ r? \ N \ s \ r? \ N)/s ", $ s,-1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE); $ d = array (PHP_EOL .'
','
'. PHP_EOL); foreach ($ ar as $ I = >$ v) {if ($ I) echo $ d [$ I % 2]; echo $ v ;} echo $ d [0];
Untitled Document