Preparation of mini search engines with PHP & XML (1)

xiaoxiao2021-03-06  78

Preparation of mini search engines with PHP & XML (1)

First, I know XML, everyone may be very strange to XML, I don't want the system to explain XML why, I just introduced some concepts used in this article, if you have used XML, even beginners. You can also skip this chapter. Talking about XML, I may wish to give you a familiar HTML code. (1) (2) Page title </ title> (3) <body> (4) <p> <center> <font color = "red"> text </ font> </ center> </ p> (5) <a href="www.yahoo.com"> <img src = "yahoo.gif" /> </a> (6) </ body> (7) </ html> above Segment code can comply with XML rules from the structure. He meets the following characteristics 1. When references the same element, use consistent cases such as <center> </ center> is a defined 2, any property value (such as href = "????") "" "" "" "" "" Img ... /> Please pay attention to the end /> less or wrong code 4, all elements must nest each other, just like writing the loop, and all elements must be nested in the root element. All of the contents of the code are nested in <HTML> </ HTML>. 5, the name of the element (ie, the above Body a P IMG, etc.) should begin with letters. In fact, it is best to be an English word, please pay attention to case. How, XML is not too annoying, you can understand that he is a good structure type of a tree containing data. Ok, everyone is familiar with the XML used in our program. <LINKS> Network Mania Mystery Your Search Engine Constructs <Web Memo = "MEMO1" URL = "> Name1 </ Web> <SUB> Computer Network <Web Memo =" Nemo2 "> Name2 <SUB MEB > <Sub> programming language <Web Memo = "Memo3"> Name3 </ Web> <sub> php <web url = "http://www.phpbuilder.com/" MEMO = "[English] PHP development resource. "Www.phpbuilder.com </ Web> <web url =" http://www.fokus.gmd.de "Memo =" [English] PHP Development Manual.</p> <p>"PHP MANUAL </ Web> </ sub> </ sub> </ sub> </ links> In fact, its structure is quite simple, the root element is links, and the SUB represents a category, the web is a website information, It contains attributes, the URL represents the connection of the website, MEMO is a note information, <web> ?? </ web>, <sub> ?? </ sub> is the name of the element and the name of the website is here. Please note that he is in line with the requirements of me. Plus <? XML Version = "1.0" Encoding = "GB2312" in 1st, in the first line, add it to XYZ.XML, use IE5 or more Take a look. How, the structure of his tree is unblora. So why do our mini's search engine use him. The first reason is that I can't use MySQL in Ozen (I really embrace), second For small data volume search engines, its data is small, if used in the database, efficiency is not necessarily high. The most important point is that he maintains quite simple, reduce manpower, and not writing Cut coins maintenance program, for example, we have to add a category or page, just edit the text file, plus a <web> ??? </ web> or <sub> ???? </ sub> Yes, and if you want to move a category to another, we will not take this part of the SUB, CTRL-X, CTRL-V. In fact, XML function I only After using a little fur, I will give you a more deep article. II. How PHP parses XML Note: This chapter is based on the NetEase Virtual Community (I am too lazy to knock), two types of XML parsers Basic Type: Tree-based parser: Convert XML document into a tree structure. Such parser analyzes the entire article while providing an API to access each element of the tree. Its generic standard is DOM (documentation) Object mode). Used JavaScript may be used through XMLDOM. Event-based parser: Treat XML documents as a series of events. When a special event occurs, the parser will call the function provided by the developer. Based on event The parser has a data set view of an XML document, that is, it focuses on the data section of the XML document, not its structure. These parsers process the document from the head to the tail, and will be similar to the beginning of the element, the end of the element, The start of feature data. - The event is reported to the application via a callback function. Heral is an "Hello-World" XML Sample: <greeting> Hello World </ greeting> Event-based parser will report as three events: Start element: Greeting CDATA item, the value is: Hello World End Element: Greeting is not like a tree-based parser The event-based parser does not produce the structure of the document.</p> <p>In CDATA, event-based parsers do not allow you to get information about the parent element Greeting. However, it provides a lower-level access, which makes it better to use resources and access faster. In this way, there is no need to put the entire document into memory; in fact, the entire document can even be greater than the actual memory value. Prepare a function for generating an XML parser instance as XML_Parser_Create (). This instance will be used for all functions. This idea is very similar to the connection tag of the MySQL function in PHP. Event-based parsers are usually required to register the callback function before parsing the document - calls when specific events occur. Expat no exceptions, it defines the following seven possible events: the beginning and end of the character objects XML parsing function describes the elements xml_set_element_handler () element data xml_set_character_data_handler () to start an external entity xml_set_external_entity_ref_handler character data () external entities appear External unparsed entity xml_set_unparsed_entity_decl_handler () Unconcerned external entity appearance processing command XML_SET_PROCESSING_INSTRUCTION_HANDLER () Processing Declaration Declaration XML_SET_NOTATION_DECL_HANDLER () Declaration Default XML_SET_DEFAULT_HANDLER () Other Events No Events All Tune Functions All callback functions must be used as an instance of the parser The first parameter (there are other parameters). See PHP instructions for more detail. The following examples are used in the example of the XML element structure (Element Structure) taken from the PHP manual example, he is the basic structure of our search engine, but I will not comment, because we will introduce it next chapter.</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-109776.html</div><div class="plugin d-flex justify-content-center mt-3"></div><hr><div class="row"><div class="col-lg-12 text-muted mt-2"><i class="icon-tags mr-2"></i><span class="badge border border-secondary mr-2"><h2 class="h6 mb-0 small"><a class="text-secondary" href="tag-2.html">9cbs</a></h2></span></div></div></div></div><div class="card card-postlist border-white shadow"><div class="card-body"><div class="card-title"><div class="d-flex justify-content-between"><div><b>New Post</b>(<span class="posts">0</span>) </div><div></div></div></div><ul class="postlist list-unstyled"> </ul></div></div><div class="d-none threadlist"><input type="checkbox" name="modtid" value="109776" checked /></div></div></div></div></div><footer class="text-muted small bg-dark py-4 mt-3" id="footer"><div class="container"><div class="row"><div class="col">CopyRight © 2020 All Rights Reserved </div><div class="col text-right">Processed: <b>0.042</b>, SQL: <b>9</b></div></div></div></footer><script src="./lang/en-us/lang.js?2.2.0"></script><script src="view/js/jquery.min.js?2.2.0"></script><script src="view/js/popper.min.js?2.2.0"></script><script src="view/js/bootstrap.min.js?2.2.0"></script><script src="view/js/xiuno.js?2.2.0"></script><script src="view/js/bootstrap-plugin.js?2.2.0"></script><script src="view/js/async.min.js?2.2.0"></script><script src="view/js/form.js?2.2.0"></script><script> var debug = DEBUG = 0; var url_rewrite_on = 1; var url_path = './'; var forumarr = {"1":"Tech"}; var fid = 1; var uid = 0; var gid = 0; xn.options.water_image_url = 'view/img/water-small.png'; </script><script src="view/js/wellcms.js?2.2.0"></script><a class="scroll-to-top rounded" href="javascript:void(0);"><i class="icon-angle-up"></i></a><a class="scroll-to-bottom rounded" href="javascript:void(0);" style="display: inline;"><i class="icon-angle-down"></i></a></body></html><script> var forum_url = 'list-1.html'; var safe_token = 'CUjdi1Bly9v_2BlQOUjjdvNyHVNFk6hNqJbhOrHo4P_2BebuRu24vTqeLP5pNrQRAEeMUhAG8C6XqrH5adqk'; var body = $('body'); body.on('submit', '#form', function() { var jthis = $(this); var jsubmit = jthis.find('#submit'); jthis.reset(); jsubmit.button('loading'); var postdata = jthis.serializeObject(); $.xpost(jthis.attr('action'), postdata, function(code, message) { if(code == 0) { location.reload(); } else { $.alert(message); jsubmit.button('reset'); } }); return false; }); function resize_image() { var jmessagelist = $('div.message'); var first_width = jmessagelist.width(); jmessagelist.each(function() { var jdiv = $(this); var maxwidth = jdiv.attr('isfirst') ? first_width : jdiv.width(); var jmessage_width = Math.min(jdiv.width(), maxwidth); jdiv.find('img, embed, iframe, video').each(function() { var jimg = $(this); var img_width = this.org_width; var img_height = this.org_height; if(!img_width) { var img_width = jimg.attr('width'); var img_height = jimg.attr('height'); this.org_width = img_width; this.org_height = img_height; } if(img_width > jmessage_width) { if(this.tagName == 'IMG') { jimg.width(jmessage_width); jimg.css('height', 'auto'); jimg.css('cursor', 'pointer'); jimg.on('click', function() { }); } else { jimg.width(jmessage_width); var height = (img_height / img_width) * jimg.width(); jimg.height(height); } } }); }); } function resize_table() { $('div.message').each(function() { var jdiv = $(this); jdiv.find('table').addClass('table').wrap('<div class="table-responsive"></div>'); }); } $(function() { resize_image(); resize_table(); $(window).on('resize', resize_image); }); var jmessage = $('#message'); jmessage.on('focus', function() {if(jmessage.t) { clearTimeout(jmessage.t); jmessage.t = null; } jmessage.css('height', '6rem'); }); jmessage.on('blur', function() {jmessage.t = setTimeout(function() { jmessage.css('height', '2.5rem');}, 1000); }); $('#nav li[data-active="fid-1"]').addClass('active'); </script>