
{"id":4577,"date":"2015-07-13T16:05:50","date_gmt":"2015-07-13T16:05:50","guid":{"rendered":"http:\/\/tapchicntt.com\/?p=4577"},"modified":"2023-08-17T08:44:29","modified_gmt":"2023-08-17T01:44:29","slug":"php-bai-2-cau-truc-php-co-ban","status":"publish","type":"post","link":"https:\/\/tapchicntt.com\/php-bai-2-cau-truc-php-co-ban\/","title":{"rendered":"[php] B\u00e0i 2: C\u1ea5u tr\u00fac PHP c\u01a1 b\u1ea3n"},"content":{"rendered":"\n<p>M\u00e3 ngu\u1ed3n PHP \u0111\u01b0\u1ee3c th\u1ef1c thi tr\u00ean m\u00e1y ch\u1ee7, v\u00e0 tr\u1ea3 v\u1ec1 k\u1ebft qu\u1ea3 HTML cho tr\u00ecnh duy\u1ec7t.<br><\/p>\n\n\n\n<!--more-->\n\n\n\n<h2 class=\"wp-block-heading\">C\u00fa ph\u00e1p PHP C\u01a1 b\u1ea3n<\/h2>\n\n\n\n<p>M\u1ed9t m\u00e3 ngu\u1ed3n PHP c\u00f3 th\u1ec3 \u0111\u1eb7t b\u1ea5t c\u1ee9 n\u01a1i n\u00e0o trong t\u00e0i li\u1ec7u. M\u00e3 ngu\u1ed3n PHP \u0111\u01b0\u1ee3c b\u1eaft \u0111\u1ea7u b\u1eb1ng\u00a0<strong><code>&lt;?php<\/code><\/strong>\u00a0v\u00e0 k\u1ebft th\u00fac b\u1eb1ng <strong><code>?><\/code><\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\n&lt;?php\n   \/\/ M\u00e3 ngu\u1ed3n PHP \u0111\u1eb7t t\u1ea1i \u0111\u00e2y\n?&gt;\n<\/pre><\/div>\n\n\n<p>T\u1eadp tin m\u1eb7c \u0111\u1ecbnh c\u1ee7a ng\u00f4n ng\u1eef PHP c\u00f3 \u0111u\u00f4i m\u1ee1 r\u1ed9ng l\u00e0 &#8220;.php&#8221;<\/p>\n\n\n\n<p>M\u1ed9t file PHP th\u00f4ng th\u01b0\u1eddng ch\u1ee9a c\u00e1c th\u1ebb HTML, v\u00e0 m\u1ed9t s\u1ed1 m\u00e3 k\u1ecbch b\u1ea3n PHP.<\/p>\n\n\n\n<p>D\u01b0\u1edbi \u0111\u00e2y, ch\u00fang ta c\u00f3 m\u1ed9t v\u00ed d\u1ee5 v\u1ec1 m\u1ed9t t\u1eadp tin PHP \u0111\u01a1n gi\u1ea3n, v\u1edbi m\u1ed9t k\u1ecbch b\u1ea3n PHP c\u00f3 s\u1eed d\u1ee5ng m\u1ed9t ch\u1ee9c n\u0103ng \u0111\u01b0\u1ee3c x\u00e2y d\u1ef1ng trong PHP l\u00e0 l\u1ec7nh &#8220;echo&#8221;:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\n&lt;!DOCTYPE html&gt;\n&lt;html&gt;\n   &lt;body&gt;\n\n      &lt;h1&gt;My first PHP page&lt;\/h1&gt;\n\n      &lt;?php\n         echo &quot;Hello World!&quot;;\n      ?&gt;\n\n   &lt;\/body&gt;\n&lt;\/html&gt;\n<\/pre><\/div>\n\n\n<p><strong>L\u01b0u \u00fd<\/strong>: k\u1ebft th\u00fac m\u1ed9t d\u00f2ng l\u1ec7nh PHP b\u1eb1ng m\u1ed9t d\u1ea5u ch\u1ea5m ph\u1ea9y (;).<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Ch\u00fa th\u00edch trong PHP<\/h2>\n\n\n\n<p>Ch\u00fa th\u00edch trong m\u00e3 PHP l\u00e0 m\u1ed9t d\u00f2ng kh\u00f4ng \u0111\u01b0\u1ee3c th\u1ef1c hi\u1ec7n. M\u1ee5c \u0111\u00edch duy nh\u1ea5t c\u1ee7a n\u00f3 l\u00e0 \u0111\u1ec3 ch\u00fa th\u00edch cho ng\u01b0\u1eddi l\u1eadp tr\u00ecnh bi\u1ebft h\u1ecd \u0111ang th\u1ef1c hi\u1ec7n nh\u1eefng g\u00ec.<\/p>\n\n\n\n<p>B\u00ecnh lu\u1eadn c\u00f3 th\u1ec3 \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng \u0111\u1ec3:<\/p>\n\n\n\n<p>&#8211; Cho g\u01b0\u1eddi kh\u00e1c hi\u1ec3u nh\u1eefng g\u00ec b\u1ea1n \u0111ang l\u00e0m.<br>&#8211; Nh\u1eafc nh\u1edf b\u1ea3n th\u00e2n v\u1ec1 nh\u1eefng g\u00ec b\u1ea1n \u0111\u00e3 l\u00e0m.<br>&#8211; H\u1ea7u h\u1ebft c\u00e1c l\u1eadp tr\u00ecnh vi\u00ean \u0111\u00e3 c\u00f3 kinh nghi\u1ec7m tr\u1edf l\u1ea1i v\u1edbi c\u00f4ng vi\u1ec7c c\u1ee7a m\u00ecnh m\u1ed9t ho\u1eb7c hai n\u0103m sau \u0111\u00f3 v\u00e0 ph\u1ea3i t\u00ecm ra nh\u1eefng g\u00ec h\u1ecd \u0111\u00e3 l\u00e0m. Ch\u00fa th\u00edch c\u00f3 th\u1ec3 nh\u1eafc nh\u1edf b\u1ea1n v\u1ec1 nh\u1eefng g\u00ec b\u1ea1n \u0111ang l\u00e0m.<\/p>\n\n\n\n<p>B\u1ea1n c\u00f3 nhi\u1ec1u c\u00e1ch \u0111\u1ec3 ghi ch\u00fa:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\n&lt;!DOCTYPE html&gt;\n&lt;html&gt;\n   &lt;body&gt;\n\n      &lt;?php\n      \n      \/\/ Ghi ch\u00fa 1 d\u00f2ng\n\n      # Ghi ch\u00fa 1 d\u00f2ng\n\n      \/*\n\n      \u0110o\u1ea1n ghi ch\u00fa \n\n      *\/\n\n      \/\/ You can also use comments to leave out parts of a code line\n      $x = 5 \/* + 15 *\/ + 5;\n      echo $x;\n      ?&gt;\n\n   &lt;\/body&gt;\n&lt;\/html&gt;\n<\/pre><\/div>\n\n\n<p>Trong PHP, t\u1ea5t c\u1ea3 c\u00e1c t\u1eeb kh\u00f3a (v\u00ed d\u1ee5: if, else, while, echo&#8230;v.v), classes, functions l\u00e0 kh\u00f4ng ph\u00e2n bi\u1ec7t ch\u1eef hoa hay ch\u1eef th\u01b0\u1eddng.<\/p>\n\n\n\n<p>V\u00ed d\u1ee5 sao \u0111\u00e2y l\u00e0 ho\u00e0n to\u00e0n \u0111\u00fang:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\n&lt;!DOCTYPE html&gt;\n&lt;html&gt;\n   &lt;body&gt;\n\n      &lt;?php\n\n      ECHO &quot;Hello World!&lt;br&gt;&quot;;\n      echo &quot;Hello World!&lt;br&gt;&quot;;\n      EcHo &quot;Hello World!&lt;br&gt;&quot;;\n\n      ?&gt;\n\n   &lt;\/body&gt;\n&lt;\/html&gt;\n<\/pre><\/div>\n\n\n<p>Nh\u01b0ng bi\u1ebfn c\u1ee7a php c\u00f3 ph\u00e2n bi\u1ec7t ch\u1eef hoa v\u00e0 ch\u1eef th\u01b0\u1eddng, n\u00ean v\u00ed d\u1ee5 d\u01b0\u1edbi \u0111\u00e2y l\u00e0 3 bi\u1ebfn kh\u00e1c nhau, v\u00e0 ch\u1ec9 truy xu\u1ea5t bi\u1ebfn \u0111\u1ea7u ti\u00ean l\u00e0 \u0111\u00fang:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\n&lt;!DOCTYPE html&gt;\n&lt;html&gt;\n   &lt;body&gt;\n   &lt;?php\n      $color = &quot;red&quot;;\n      echo &quot;My car is &quot; . $color . &quot;&lt;br&gt;&quot;;\n      echo &quot;My house is &quot; . $COLOR . &quot;&lt;br&gt;&quot;;\n      echo &quot;My boat is &quot; . $coLOR . &quot;&lt;br&gt;&quot;;\n   ?&gt;\n   &lt;\/body&gt;\n&lt;\/html&gt;\n<\/pre><\/div>","protected":false},"excerpt":{"rendered":"<p>M\u00e3 ngu\u1ed3n PHP \u0111\u01b0\u1ee3c th\u1ef1c thi tr\u00ean m\u00e1y ch\u1ee7, v\u00e0 tr\u1ea3 v\u1ec1 k\u1ebft qu\u1ea3 HTML cho tr\u00ecnh duy\u1ec7t.<\/p>\n","protected":false},"author":6,"featured_media":4572,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[178],"tags":[],"class_list":["post-4577","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php"],"views":830,"_links":{"self":[{"href":"https:\/\/tapchicntt.com\/rest-api\/wp\/v2\/posts\/4577","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tapchicntt.com\/rest-api\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tapchicntt.com\/rest-api\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tapchicntt.com\/rest-api\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/tapchicntt.com\/rest-api\/wp\/v2\/comments?post=4577"}],"version-history":[{"count":9,"href":"https:\/\/tapchicntt.com\/rest-api\/wp\/v2\/posts\/4577\/revisions"}],"predecessor-version":[{"id":8248,"href":"https:\/\/tapchicntt.com\/rest-api\/wp\/v2\/posts\/4577\/revisions\/8248"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/tapchicntt.com\/rest-api\/wp\/v2\/media\/4572"}],"wp:attachment":[{"href":"https:\/\/tapchicntt.com\/rest-api\/wp\/v2\/media?parent=4577"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tapchicntt.com\/rest-api\/wp\/v2\/categories?post=4577"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tapchicntt.com\/rest-api\/wp\/v2\/tags?post=4577"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}