search
HomeBackend DevelopmentPHP TutorialQuickly build an scalable website based on xml+xslt+css+php_PHP tutorial

Quickly build an scalable website based on xml+xslt+css+php_PHP tutorial

Jul 13, 2016 pm 05:39 PM
txmlandseparationScalablebased onfastdatashowConstructwebsite

1.让数据与显示分离
 
test.xml 数据:
 
test title
test content
banner
sidebar
main body
end of the page
 
test.xslt 模板:
 
test
]]>
 
 
2.网页自动生成
 
php 程序读入config文件根据文件中指定的目标文件名 和 数据文件名 以及 模板文件名生成目标页面
 
config 文件:
 
test.html
test.xml
test.xslt
 
php 代码:
 
$xml_file = “../conf/config”;
$name_tag = 0;
$xml_tag = 0;
$xsl_tag = 0;
 
$name = “”;
 
$arr = Array();
 
$i = 0;
 
function startElement($parser_instance, $element_name, $attrs)
{
global $name_tag;
global $xml_tag;
global $xsl_tag;
 
switch($element_name)
{
case “NAME” :
$name_tag = 1;
break;
case “XMLFILE” :
$xml_tag = 1;
break;
case “XSLFILE” :
$xsl_tag = 1;
break;
}
}
 
function characterData($parser_instance, $xml_data)
{
global $arr;
global $name_tag;
global $xml_tag;
global $xsl_tag;
global $name;
 
$xml_data = ltrim($xml_data);
 
if ($xml_data != “”)
{
if ($name_tag == 1)
{
$arr["$xml_data"] = Array();
$name = $xml_data;
$arr["$name"][0] = $name;
$name_tag = 0;
}
 
if ($xml_tag == 1)
{
$arr["$name"][1] = $xml_data;
$xml_tag = 0;
}
 
if ($xsl_tag == 1)
{
$arr["$name"][2] = $xml_data;
$xsl_tag = 0;
}
}
}
 
function endElement($parser_instance, $element_name)
{
 
}
 
function buildHtml($name, $xml, $xsl)
{
echo “$name $xml $xsl ”;
$xslDoc = new DOMDocument();
$xslDoc->load(”$xsl”);
 
$xmlDoc = new DOMDocument();
$xmlDoc->load(”$xml”);
 
$proc = new XSLTProcessor();
$proc->importStylesheet($xslDoc);
$html = $proc->transformToXML($xmlDoc);
 
if (!($filehandler = fopen($name, “w+”)))
{
die(”could not open $name output”);
}
 
fwrite($filehandler, $html);
 
fclose($filehandler);
}
 
$parser = xml_parser_create();
 
xml_set_element_handler($parser, “startElement”, “endElement”);
xml_set_character_data_handler($parser, “characterData”);
 
if (!($filehandler = fopen($xml_file, “r”)))
{
die(”could not open XML input”);
}
 
while ($data = fread($filehandler, 4096))
{
if (!xml_parse($parser, $data, feof($filehandler)))
{
die(sprintf(”XML error: %s at line %d”,
xml_error_string(xml_get_error_code($parser)),
xml_get_current_line_number($parser)));
}
}
 
 
fclose($filehandler);
xml_parser_free($parser);
 
 
 
foreach ($arr as $sub_arr)
{
$i = 0;
foreach ($sub_arr as $obj)
{
if ($i == 0)
{
$name = $obj;
}
 
if ($i == 1)
{
$xml = $obj;
}
 
if ($i == 2)
{
$xsl = $obj;
}
 
$i++;
}
buildHtml($name, $xml, $xsl);
 
}
 
 
?>
 
 
 
3.重新规划整个页面
 
 
这样的分拆式设计可以使页面更灵活,随意修改任何部分都不会影响到其余的块,并且可以不断变换其中的某个块的数据 比如:body.xml 来生成更多新的页面, 特别适合新闻系统或论坛使用
 
top.xml:
 

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/486275.htmlTechArticle1.让数据与显示分离 test.xml 数据: xml titletest title/title contenttest content/content topbanner/top leftsidebar/left bodymain body/body endend of the page/end /xml test...
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Explain how load balancing affects session management and how to address it.Explain how load balancing affects session management and how to address it.Apr 29, 2025 am 12:42 AM

Load balancing affects session management, but can be resolved with session replication, session stickiness, and centralized session storage. 1. Session Replication Copy session data between servers. 2. Session stickiness directs user requests to the same server. 3. Centralized session storage uses independent servers such as Redis to store session data to ensure data sharing.

Explain the concept of session locking.Explain the concept of session locking.Apr 29, 2025 am 12:39 AM

Sessionlockingisatechniqueusedtoensureauser'ssessionremainsexclusivetooneuseratatime.Itiscrucialforpreventingdatacorruptionandsecuritybreachesinmulti-userapplications.Sessionlockingisimplementedusingserver-sidelockingmechanisms,suchasReentrantLockinJ

Are there any alternatives to PHP sessions?Are there any alternatives to PHP sessions?Apr 29, 2025 am 12:36 AM

Alternatives to PHP sessions include Cookies, Token-based Authentication, Database-based Sessions, and Redis/Memcached. 1.Cookies manage sessions by storing data on the client, which is simple but low in security. 2.Token-based Authentication uses tokens to verify users, which is highly secure but requires additional logic. 3.Database-basedSessions stores data in the database, which has good scalability but may affect performance. 4. Redis/Memcached uses distributed cache to improve performance and scalability, but requires additional matching

Define the term 'session hijacking' in the context of PHP.Define the term 'session hijacking' in the context of PHP.Apr 29, 2025 am 12:33 AM

Sessionhijacking refers to an attacker impersonating a user by obtaining the user's sessionID. Prevention methods include: 1) encrypting communication using HTTPS; 2) verifying the source of the sessionID; 3) using a secure sessionID generation algorithm; 4) regularly updating the sessionID.

What is the full form of PHP?What is the full form of PHP?Apr 28, 2025 pm 04:58 PM

The article discusses PHP, detailing its full form, main uses in web development, comparison with Python and Java, and its ease of learning for beginners.

How does PHP handle form data?How does PHP handle form data?Apr 28, 2025 pm 04:57 PM

PHP handles form data using $\_POST and $\_GET superglobals, with security ensured through validation, sanitization, and secure database interactions.

What is the difference between PHP and ASP.NET?What is the difference between PHP and ASP.NET?Apr 28, 2025 pm 04:56 PM

The article compares PHP and ASP.NET, focusing on their suitability for large-scale web applications, performance differences, and security features. Both are viable for large projects, but PHP is open-source and platform-independent, while ASP.NET,

Is PHP a case-sensitive language?Is PHP a case-sensitive language?Apr 28, 2025 pm 04:55 PM

PHP's case sensitivity varies: functions are insensitive, while variables and classes are sensitive. Best practices include consistent naming and using case-insensitive functions for comparisons.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool