Ec (2); 1. Generate a js file in php: & lt ;? Php $ aarray (& nbsp; array (title & gt; local news 1, ln & gt; #), & nbsp; array (title & gt; local news 2, ln & gt; #), & nbsp; array (title & gt; local news 3, ln & gt; #) & script ec (2); script
1. php generates js files:
$ A = array (
Array (''title' => ''local News 1 '', ln => ''#''),
Array (''title' => '''local news 2', ln => ''#''),
Array (''title' => '''local news 3', ln => ''#'')
); // The number of record sets can be obtained through the database in actual operations
$ News = ''var a = [''; // convert the array to the reverse Cr forward pt format.
For ($ I = 0; $ I
If ($ I = count ($ a)-1 ){
$ News. = ''{''
. "Title :''"
. $ A [$ I] [title]. "''"
.","
. "Ln :''"
. $ A [$ I] [ln]
.''''}'';
} Else {
$ News. = ''{''
. "Title :''"
. $ A [$ I] [title]. "''"
.","
. "Ln :''"
. $ A [$ I] [ln]
. '''}, '''; // If the data is not the last one, separate them with commas (,). Otherwise, the process ends.
}
}
$ News. = ''];'';
$ Fh = fopen ("file. js", "w ");
Fwrite ($ fh, $ news );
Fclose ($ fh); // write to js
?>
2. html file
Untitled document
// Define the display format, which is first hidden through display: none
// Reference js
News_obj = document. getElementById (''news '');
E = news_obj.innerHTML;
Re =/$ title/g; // regular, matching $ title
Re2 =/$ link/g; // match $ link
For (I = 0; I tmp = e. replace (re,
<