Build your own Database driven Website using PHP & My SQL: Part 2
Số trang: 239
Loại file: pdf
Dung lượng: 6.08 MB
Lượt xem: 13
Lượt tải: 0
Xem trước 10 trang đầu tiên của tài liệu này:
Thông tin tài liệu:
(BQ) Part 2 of Tài liệu Build your own Database driven Website using PHP & My SQL presents contens as: Content formatting with regular expressions; cookies, sessions, and access control; MySQL administration, advanced SQL queries, binary data. This book is your map to the twisty path that every beginner must navigate to learn PHP and MySQL today. Inviting you to refer.
Nội dung trích xuất từ tài liệu:
Build your own Database driven Website using PHP & My SQL: Part 2 www.it-ebooks.info 8 Chapter Content Formatting with Regular Expressions We’re almost there! We’ve designed a database to store jokes, organized them into categories, and tracked their authors. We’ve learned how to create a web page that displays this library of jokes to site visitors. We’ve even developed a set of web pages that a site administrator can use to manage the joke library without having to know anything about databases. In so doing, we’ve built a site that frees the resident webmaster from continually having to plug new content into tired HTML page templates, and from maintaining an unmanageable mass of HTML files. The HTML is now kept completely separate from the data it displays. If you want to redesign the site, you simply have to make the changes to the HTML contained in the PHP templates that you’ve constructed. A change to one file (for example, modifying the footer) is immediately reflected in the page layouts of all pages in the site. Only one task still requires the knowledge of HTML: content formatting. On any but the simplest of web sites, it will be necessary to allow content (in our case study, jokes) to include some sort of formatting. In a simple case, this mightLicensed to botuongxulang@yahoo.com www.it-ebooks.info 242 Build Your Own Database Driven Web Site Using PHP & MySQL merely be the ability to break text into paragraphs. Often, however, content providers will expect facilities such as bold or italic text, hyperlinks, and so on. Supporting these requirements with our current code is deceptively easy. In the past couple of chapters, we’ve used htmlout to output user-submitted content: chapter6/jokes-helpers/jokes.html.php (excerpt) If, instead, we just echo out the raw content pulled from the database, we can enable administrators to include formatting in the form of HTML code in the joke text: Following this simple change, a site administrator could include HTML tags that would have their usual effect on the joke text when inserted into a page. But is this really what we want? Left unchecked, content providers can do a lot of damage by including HTML code in the content they add to your site’s database. Particularly if your system will be enabling non-technical users to submit content, you’ll find that invalid, obsolete, and otherwise inappropriate code will gradually infest the pristine web site you set out to build. With one stray tag, a well-meaning user could tear apart the layout of your site. In this chapter, you’ll learn about several new PHP functions that specialize in finding and replacing patterns of text in your site’s content. I’ll show you how to use these capabilities to provide for your users a simpler markup language that’s better suited to content formatting. By the time we’ve finished, we’ll have completed a content management system that anyone with a web browser can use—no know- ledge of HTML required. Regular Expressions To implement our own markup language, we’ll have to write some PHP code to spot our custom tags in the text of jokes and replace them with their HTML equival- ents. For tackling this sort of task, PHP includes extensive support for regular ex- pressions. A regular expression is a string of text that describes a pattern that may occur in text content like our jokes.Licensed to botuongxulang@yahoo.com www.it-ebooks.info Content Formatting with Regular Expressions 243 The language of regular expression is cryptic enough that, once you master it, you may feel as if you’re able to weave magical incantations with the code that you write. To begin with, however, let’s start with some very simple regular expressions. This is a regular expression that searches for the text “PHP” (without the quotes): /PHP/ Fairly simple, you would say? It’s the text for which you want to search surrounded by a pair of matching delimiters. Traditionally, sl ...
Nội dung trích xuất từ tài liệu:
Build your own Database driven Website using PHP & My SQL: Part 2 www.it-ebooks.info 8 Chapter Content Formatting with Regular Expressions We’re almost there! We’ve designed a database to store jokes, organized them into categories, and tracked their authors. We’ve learned how to create a web page that displays this library of jokes to site visitors. We’ve even developed a set of web pages that a site administrator can use to manage the joke library without having to know anything about databases. In so doing, we’ve built a site that frees the resident webmaster from continually having to plug new content into tired HTML page templates, and from maintaining an unmanageable mass of HTML files. The HTML is now kept completely separate from the data it displays. If you want to redesign the site, you simply have to make the changes to the HTML contained in the PHP templates that you’ve constructed. A change to one file (for example, modifying the footer) is immediately reflected in the page layouts of all pages in the site. Only one task still requires the knowledge of HTML: content formatting. On any but the simplest of web sites, it will be necessary to allow content (in our case study, jokes) to include some sort of formatting. In a simple case, this mightLicensed to botuongxulang@yahoo.com www.it-ebooks.info 242 Build Your Own Database Driven Web Site Using PHP & MySQL merely be the ability to break text into paragraphs. Often, however, content providers will expect facilities such as bold or italic text, hyperlinks, and so on. Supporting these requirements with our current code is deceptively easy. In the past couple of chapters, we’ve used htmlout to output user-submitted content: chapter6/jokes-helpers/jokes.html.php (excerpt) If, instead, we just echo out the raw content pulled from the database, we can enable administrators to include formatting in the form of HTML code in the joke text: Following this simple change, a site administrator could include HTML tags that would have their usual effect on the joke text when inserted into a page. But is this really what we want? Left unchecked, content providers can do a lot of damage by including HTML code in the content they add to your site’s database. Particularly if your system will be enabling non-technical users to submit content, you’ll find that invalid, obsolete, and otherwise inappropriate code will gradually infest the pristine web site you set out to build. With one stray tag, a well-meaning user could tear apart the layout of your site. In this chapter, you’ll learn about several new PHP functions that specialize in finding and replacing patterns of text in your site’s content. I’ll show you how to use these capabilities to provide for your users a simpler markup language that’s better suited to content formatting. By the time we’ve finished, we’ll have completed a content management system that anyone with a web browser can use—no know- ledge of HTML required. Regular Expressions To implement our own markup language, we’ll have to write some PHP code to spot our custom tags in the text of jokes and replace them with their HTML equival- ents. For tackling this sort of task, PHP includes extensive support for regular ex- pressions. A regular expression is a string of text that describes a pattern that may occur in text content like our jokes.Licensed to botuongxulang@yahoo.com www.it-ebooks.info Content Formatting with Regular Expressions 243 The language of regular expression is cryptic enough that, once you master it, you may feel as if you’re able to weave magical incantations with the code that you write. To begin with, however, let’s start with some very simple regular expressions. This is a regular expression that searches for the text “PHP” (without the quotes): /PHP/ Fairly simple, you would say? It’s the text for which you want to search surrounded by a pair of matching delimiters. Traditionally, sl ...
Tìm kiếm theo từ khóa liên quan:
Database driven Website Ebook Database driven Website MySQL administration Advanced SQL queries Regular expressions MySQL DatabasesTài liệu liên quan:
-
Ebok Mathematical foundation of computer science: Part 2
210 trang 32 0 0 -
Ebook Teach yourself Unix in 24 hours: Part 1
254 trang 31 0 0 -
ICT 5 Web Development - Chapter 12: Regular Expressions
13 trang 27 0 0 -
CREDITRISK+ A CREDIT RISK MANAGEMENT FRAMEWORK
72 trang 26 0 0 -
287 trang 25 0 0
-
Ebook Designing active server pages - Scott Mitchell
362 trang 25 0 0 -
Ebook GAWK: Effective AWK programming (A user's guide for GNU AWK) - Part 1
250 trang 23 0 0 -
Ebook Complete JavaScript: Tips and secrets for professionals
416 trang 22 0 0 -
25 trang 19 0 0
-
Build your own Database driven Website using PHP & My SQL: Part 1
268 trang 19 0 0