- Создаем динамические веб-сайты с помощью PHP, MySQL, JavaScript, CSS и HTML5.
- Saved searches
- Use saved searches to filter your results more quickly
- License
- MatiasNAmendola/HTML5-for-PHP
- Name already in use
- Sign In Required
- Launching GitHub Desktop
- Launching GitHub Desktop
- Launching Xcode
- Launching Visual Studio Code
- Latest commit
- Git stats
- Files
- README.md
- About
- How to Use PHP with HTML5 Programming
- Getting the Time, PHP Style
- Time: "; print date("h:i"); print "
- Embedding PHP inside HTML
- View the results
- Getting the Time, PHP Style
- Date: 07-05
- Time: 03:50
- About This Article
- This article is from the book:
- About the book author:
Создаем динамические веб-сайты с помощью PHP, MySQL, JavaScript, CSS и HTML5.
Научитесь создавать интерактивные сайты, активно работающие с данными, воплощая в них мощные комбинации свободно распространяемых технологий и веб-стандартов.
Для этого достаточно обладать базовыми знаниями языка HTML. Это популярное и доступное пособие поможет вам уверенно освоить динамическое веб-программирование с применением самых современных языков и технологий: PHP, MySQL, JavaScript, CSS и HTML5.
С каждой из упомянутых технологий вы познакомитесь отдельно, научитесь применять их в комбинации друг с другом, а по ходу изложения освоите ценные практические приемы веб-программирования.
В конце книги весь изученный материал будет обобщен: вы создадите полнофункциональный сайт, работающий по принципу социальной сети. Изучите важнейшие аспекты языка PHP и основы объектно-ориентированного программирования.
Откройте для себя базу данных MySQL. Управляйте cookie-файлами и сеансами, обеспечивайте высокий уровень безопасности. Пользуйтесь фундаментальными возможностями языка JavaScript.
Применяйте вызовы AJAX, чтобы значительно повысить динамику вашего сайта. Изучите основы CSS для форматирования и оформления ваших страниц.Познакомьтесь с возможностями HTML5: геолокацией, работой с аудио и видео, холстом.
Фактически любой человек, стремящийся изучить основные принципы, заложенные в основу технологии Web 2.0, известной как AJAX, сможет получить весь-AJAX, сможет получить весьма обстоятельные сведения об основных технологиях: PHP, MySQL, JavaScript, CSS и HTML5, а также изучить основы библиотеки jQuery.
Эта книга предназначена для тех, кто хочет изучить способы создания эффективных и динамичных сайтов. Сюда можно отнести веб-мастеров или специалистов по графическому дизайну, которым уже приходилось создавать статические сайты и у которых есть желание вывести свое мастерство на следующий уровень.
Saved searches
Use saved searches to filter your results more quickly
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.
Create dynamic, valid HTML5 markup with a simple an intuitive PHP API
License
MatiasNAmendola/HTML5-for-PHP
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Sign In Required
Please sign in to use Codespaces.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching Xcode
If nothing happens, download Xcode and try again.
Launching Visual Studio Code
Your codespace will open once ready.
There was a problem preparing your codespace, please try again.
Latest commit
Git stats
Files
Failed to load latest commit information.
README.md
Create dynamic, well-formatted HTML5 markup with a simple an intuitive PHP API. This is a fork/rewrite of the Gagawa project. HTML5-for-PHP is a concise, flexible and easy to remember API which makes it possible to create simple markup (such as a link) or more complex structures (such a table, document or nested list). All tags and attribute names are validated against the current HTML5 specification.
This library requires a webserver running PHP 5.3+. Also, the root namespace for the library is HTML5 .
Simply include the html.php file.
###Basic To create an HTML node, simply call global html method, passing in the tag name and then any attributes.
echo html('img src=home.jpg'); echo html('img', 'src=home.jpg'); echo html('img', array('src'=>'home.jpg'));
All of these examples would output:
There are dfferent ways to add attributes for HTML container nodes such as
, , or in the example below, .
echo html('nav title="Navigation" 'Welcome');
echo html('nav', 'Welcome', array('title'=>'Navigation', 'class'=>'main'));
$nav = html('nav', 'Welcome'); $nav->class = 'main'; $nav->title = 'Navigation'; echo $nav;
All of these examples output the same markup:
nav title pl-s">Navigation" class pl-s">main">Welcomenav>
Any HTML5 container tags (such as
, , or ) can have child elements. These elements can be strings or other HTML5 element objects.
$label = html('span', 'Website!'); $link = html('a', $label); $link->href = 'http://example.com'; echo $link;
Alternatively, use the addChild method for any container tag.
$link = html('a'); $link->href = 'http://example.com'; $link->addChild(html('span', 'Website!')); echo $link;
Or appendTo to target a container to be added to:
$link = html('a'); $link->href = 'http://example.com'; html('span', 'Website!')->appendTo($link); echo $link;
All examples would output:
a href pl-s">http://example.com">span>Website!span>a>
Tag names can optionally have CSS-style class and id selectors:
echo html('a#example'); // echo html('span.small'); // echo html('span.small.label'); // echo html('span#example.small.label'); //
####For self-closing elements (e.g.
, )
- $tag string The name of the valid HTML5 element which can contain CSS selectors or short-hand attribute string.
- $attributes array|string (optional) Collection of element attributes
Returns a HTML\Elements\Node object.
- setAttribute($name, $value) Set an attribute by name and value.
- setAttributes($values) Set an associative array of name/value pairs.
- setData($name, $value) Set data-* fields on the HTML5 element.
- getData($name) Get the data-* field on the HTML5 element.
- appendTo(NodeContainer $container) Add the element to the end of a container element.
- prependTo(NodeContainer $container) Add the element to the beginning of a container element.
####For container HTML elements (e.g.
, )
html($tag, $contents=null, $attributes=null);
- $tag string The name of the valid HTML5 element which can contain CSS selectors or short-hand attribute string.
- $contents string|Node|NodeContainer (optional) The string of the contents of the tag, or another element created by html()
- $attributes array|string (optional) Collection of element attributes
Returns a HTML\Elements\NodeContainer object.
####NodeContainer Methods (extends Node )
- addChild($node) Add a Node object to the bottom of the collection of nodes
- addChildAt($node, $index) Add a Node object at a specific zero-based index
- removeChild($node) Remove a particular node from the container
- removeChildAt($index) Remove a node by zero-based index
- removeChildren() Remove all children from the container
- getChildren() Get the collection of all Node objects
- getChildAt($index) Get a Node object at a specific index
The Document object is used for creating a bare-bones HTML5 document.
new HTML/Components/Document($title='', $charset='utf-8');
- $title string (optional) The title of the document
- $charset string (optional) The HTML character set to use
- head NodeContainer The document’s element
- body NodeContainer The document’s element
- title NodeContainer The document’s element
use HTML/Components/Document; $doc = new Document('Untitled'); $doc->head->addChild(html('script src=main.js')); $doc->body->addChild(html('div#frame')); echo $doc;
new HTML/Components/SimpleList($elements, $attributes=null, $type pl-s">ul");
- $elements array The collection of strings or other HTML elements
- $attributes array|string (optional) Collection of element attributes
- $type string (optional) A value of either «ul» or «ol»
new HTML/Components/Table($data, $headers=null, $checkbox=null);
- $data array The collection of associative-arrays with key/value pairs
- $headers array (optional) The names of the header labels
- $checkbox string (optional) The name of the key name in the data to replace with a checkbox, for instance «id»
// Create a sample table with some rows of dummy data $table = new Table( array( array('id'=>1, 'first'=>'James', 'last'=>'Smith'), array('id'=>2, 'first'=>'Mary', 'last'=>'Denver'), array('id'=>3, 'first'=>'Charlie', 'last'=>'Rose') ), array('ID', 'First Name', 'Last Name') );
Copyright (c) 2013 Matt Moore and CloudKid, LLC
Released under the MIT License.
About
Create dynamic, valid HTML5 markup with a simple an intuitive PHP API
How to Use PHP with HTML5 Programming
PHP is a different language than HTML5, but the two are very closely related. It may be best to think of PHP as an extension that allows you to do things you cannot do easily in HTML.
Every time you run getTime.php, it generates the current date and time and returns these values to the user. This would not be possible in ordinary HTML because the date and time (by definition) always change. While you could make this page using JavaScript, the PHP approach is useful for demonstrating how PHP works. First, take a look at the PHP code:
Getting the Time, PHP Style
Date: "; print date("m-d"); print " n"; print "Time: "; print date("h:i"); print "
"; ?>
Embedding PHP inside HTML
The PHP code has some interesting characteristics:
- It’s structured mainly as an HTML document. The doctype definition, document heading, and initial H1 heading are all ordinary HTML. Begin your page as you do any HTML document. A PHP page can have as much HTML code as you wish. (You might have no PHP at all!) The only thing the PHP designation does is inform the server that PHP code may be embedded into the document.
- PHP code is embedded into the page. You can switch from HTML to PHP with the tag. Signify the end of the PHP code with the ?> symbol.
- The PHP code creates HTML. PHP is usually used to create HTML code. In effect, PHP takes over and prints out the part of the page that can’t be created in static HTML. The result of a PHP fragment is usually HTML code.
- The date() function returns the current date with a specific format. The format string indicates how the date should be displayed.
- The result of the PHP code will be an HTML document. When the PHP code is finished, it will be replaced by HTML code.
View the results
If you view showDate.php in your browser, you won’t see the PHP code. Instead, you’ll see an HTML page. It’s even more interesting when you use your browser to view the page source. Here’s what you’ll see:
Getting the Time, PHP Style
Date: 07-05
Time: 03:50
The remarkable thing is what you don’t see. When you look at the source of showDate.php in your browser, the PHP is completely gone! This is one of the most important points about PHP: The browser never sees any of the PHP. The PHP code is converted completely to HTML before anything is sent to the browser.
This means that you don’t need to worry about whether a user’s browser understands PHP. Because the user never sees your PHP code (even if he views the HTML source), PHP code works on any browser, and is a touch more secure than client-side code.
About This Article
This article is from the book:
About the book author:
Andy Harris taught himself programming because it was fun. Today he teaches computer science, game development, and web programming at the university level; is a technology consultant for the state of Indiana; has helped people with disabilities to form their own web development companies; and works with families who wish to teach computing at home.