Php + javascript static simple example-PHP source code

Source: Internet
Author: User
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





$ Title


// 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,

<

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.