{"id":65,"date":"2024-07-13T19:12:09","date_gmt":"2024-07-13T19:12:09","guid":{"rendered":"https:\/\/shaplakanon.com\/wdc\/?p=65"},"modified":"2024-07-13T19:12:10","modified_gmt":"2024-07-13T19:12:10","slug":"php-syntax-and-variables","status":"publish","type":"post","link":"https:\/\/shaplakanon.com\/wdc\/php-syntax-and-variables\/","title":{"rendered":"PHP syntax and variables"},"content":{"rendered":"\n<p>PHP is a popular scripting language used to create dynamic web pages. This tutorial will help you understand the basics of PHP, including its syntax, how to add comments, and how to use variables.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>1. Introduction to PHP<\/strong><\/h4>\n\n\n\n<p>PHP stands for &#8220;Hypertext Preprocessor.&#8221; It is a server-side language, which means it runs on the server and generates HTML to be displayed in the browser. PHP is embedded within HTML code and is executed on the server.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>2. Basic PHP Syntax<\/strong><\/h4>\n\n\n\n<p>PHP code is placed inside <code>&lt;?php ... ?&gt;<\/code> tags. Here&#8217;s a simple example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!DOCTYPE html&gt;\n&lt;html&gt;\n&lt;body&gt;\n\n&lt;?php\necho \"Hello, World!\";\n?&gt;\n\n&lt;\/body&gt;\n&lt;\/html&gt;<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>&lt;?php ... ?><\/code>: This tells the server to interpret the code inside as PHP.<\/li>\n\n\n\n<li><code>echo \"Hello, World!\";<\/code>: This prints &#8220;Hello, World!&#8221; to the web page.<\/li>\n<\/ul>\n\n\n\n<p><strong>Note:<\/strong> Each PHP statement ends with a semicolon (<code>;<\/code>).<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>3. PHP Comments<\/strong><\/h4>\n\n\n\n<p>Comments are lines of text within your code that are not executed. They are useful for adding notes and explanations. PHP supports two types of comments:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Single-line comments:<\/strong> Use <code>\/\/<\/code> or <code>#<\/code>.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>  &lt;?php\n  \/\/ This is a single-line comment\n  # This is also a single-line comment\n  echo \"Hello, World!\";\n  ?&gt;<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Multi-line comments:<\/strong> Use <code>\/* ... *\/<\/code>.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>  &lt;?php\n  \/* This is a multi-line comment\n     that spans multiple lines *\/\n  echo \"Hello, World!\";\n  ?&gt;<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>4. PHP Variables<\/strong><\/h4>\n\n\n\n<p>Variables are used to store data. In PHP, a variable starts with a dollar sign (<code>$<\/code>), followed by the variable name.<\/p>\n\n\n\n<p><strong>Creating Variables:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\n$txt = \"Hello, World!\";\n$number = 5;\n?&gt;<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>$txt<\/code>: A variable that stores the string &#8220;Hello, World!&#8221;.<\/li>\n\n\n\n<li><code>$number<\/code>: A variable that stores the number 5.<\/li>\n<\/ul>\n\n\n\n<p><strong>Using Variables:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\n$txt = \"Hello, World!\";\n$number = 5;\n\necho $txt; \/\/ Outputs: Hello, World!\necho \"&lt;br&gt;\"; \/\/ Outputs a line break\necho $number; \/\/ Outputs: 5\n?&gt;<\/code><\/pre>\n\n\n\n<p><strong>Variable Naming Rules:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Variable names must start with a letter or an underscore (<code>_<\/code>).<\/li>\n\n\n\n<li>Variable names can only contain letters, numbers, and underscores.<\/li>\n\n\n\n<li>Variable names are case-sensitive (<code>$txt<\/code> and <code>$TXT<\/code> are different variables).<\/li>\n<\/ul>\n\n\n\n<p><strong>String Concatenation:<\/strong><\/p>\n\n\n\n<p>To combine (concatenate) strings, use the dot (<code>.<\/code>) operator.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\n$txt1 = \"Hello,\";\n$txt2 = \"World!\";\necho $txt1 . \" \" . $txt2; \/\/ Outputs: Hello, World!\n?&gt;<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>5. Practical Example: Greeting Message<\/strong><\/h4>\n\n\n\n<p>Let&#8217;s create a simple PHP script that greets a user by name.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!DOCTYPE html&gt;\n&lt;html&gt;\n&lt;body&gt;\n\n&lt;?php\n$name = \"Alice\"; \/\/ Variable storing the user's name\necho \"Hello, \" . $name . \"!\"; \/\/ Outputs: Hello, Alice!\n?&gt;\n\n&lt;\/body&gt;\n&lt;\/html&gt;<\/code><\/pre>\n\n\n\n<p>In this example, the variable <code>$name<\/code> holds the user&#8217;s name &#8220;Alice&#8221;, and <code>echo<\/code> prints the greeting message.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">Summary<\/h3>\n\n\n\n<p>In this tutorial, we covered the basics of PHP:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Syntax:<\/strong> Embedding PHP code within HTML.<\/li>\n\n\n\n<li><strong>Comments:<\/strong> Adding notes using single-line and multi-line comments.<\/li>\n\n\n\n<li><strong>Variables:<\/strong> Storing and using data with variables.<\/li>\n<\/ol>\n\n\n\n<p>By practicing these basics, you&#8217;ll be on your way to creating dynamic web pages with PHP. Continue exploring more advanced topics and examples to enhance your PHP skills. Happy coding!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PHP is a popular scripting language used to create dynamic web pages. This tutorial will help you understand the basics [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[17],"tags":[],"class_list":["post-65","post","type-post","status-publish","format-standard","hentry","category-php"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>PHP syntax and variables - Web Development Course<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/shaplakanon.com\/wdc\/php-syntax-and-variables\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"PHP syntax and variables - Web Development Course\" \/>\n<meta property=\"og:description\" content=\"PHP is a popular scripting language used to create dynamic web pages. This tutorial will help you understand the basics [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/shaplakanon.com\/wdc\/php-syntax-and-variables\/\" \/>\n<meta property=\"og:site_name\" content=\"Web Development Course\" \/>\n<meta property=\"article:published_time\" content=\"2024-07-13T19:12:09+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-07-13T19:12:10+00:00\" \/>\n<meta name=\"author\" content=\"ShaplaKanon\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"ShaplaKanon\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/shaplakanon.com\\\/wdc\\\/php-syntax-and-variables\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/shaplakanon.com\\\/wdc\\\/php-syntax-and-variables\\\/\"},\"author\":{\"name\":\"ShaplaKanon\",\"@id\":\"https:\\\/\\\/shaplakanon.com\\\/wdc\\\/#\\\/schema\\\/person\\\/f5f224239283c27426dadc2e4cc9a825\"},\"headline\":\"PHP syntax and variables\",\"datePublished\":\"2024-07-13T19:12:09+00:00\",\"dateModified\":\"2024-07-13T19:12:10+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/shaplakanon.com\\\/wdc\\\/php-syntax-and-variables\\\/\"},\"wordCount\":330,\"commentCount\":0,\"articleSection\":[\"PHP\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/shaplakanon.com\\\/wdc\\\/php-syntax-and-variables\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/shaplakanon.com\\\/wdc\\\/php-syntax-and-variables\\\/\",\"url\":\"https:\\\/\\\/shaplakanon.com\\\/wdc\\\/php-syntax-and-variables\\\/\",\"name\":\"PHP syntax and variables - Web Development Course\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/shaplakanon.com\\\/wdc\\\/#website\"},\"datePublished\":\"2024-07-13T19:12:09+00:00\",\"dateModified\":\"2024-07-13T19:12:10+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/shaplakanon.com\\\/wdc\\\/#\\\/schema\\\/person\\\/f5f224239283c27426dadc2e4cc9a825\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/shaplakanon.com\\\/wdc\\\/php-syntax-and-variables\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/shaplakanon.com\\\/wdc\\\/php-syntax-and-variables\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/shaplakanon.com\\\/wdc\\\/php-syntax-and-variables\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/shaplakanon.com\\\/wdc\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"PHP syntax and variables\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/shaplakanon.com\\\/wdc\\\/#website\",\"url\":\"https:\\\/\\\/shaplakanon.com\\\/wdc\\\/\",\"name\":\"Web Development Course\",\"description\":\"Become a Web Developer from Home\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/shaplakanon.com\\\/wdc\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/shaplakanon.com\\\/wdc\\\/#\\\/schema\\\/person\\\/f5f224239283c27426dadc2e4cc9a825\",\"name\":\"ShaplaKanon\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/ef2c8f93a0558c2047555f674c8746b22988ace93eba9262d198d0a28236ce97?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/ef2c8f93a0558c2047555f674c8746b22988ace93eba9262d198d0a28236ce97?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/ef2c8f93a0558c2047555f674c8746b22988ace93eba9262d198d0a28236ce97?s=96&d=mm&r=g\",\"caption\":\"ShaplaKanon\"},\"sameAs\":[\"https:\\\/\\\/shaplakanon.com\\\/wdc\\\/\"],\"url\":\"https:\\\/\\\/shaplakanon.com\\\/wdc\\\/author\\\/sabahat\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"PHP syntax and variables - Web Development Course","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/shaplakanon.com\/wdc\/php-syntax-and-variables\/","og_locale":"en_US","og_type":"article","og_title":"PHP syntax and variables - Web Development Course","og_description":"PHP is a popular scripting language used to create dynamic web pages. This tutorial will help you understand the basics [&hellip;]","og_url":"https:\/\/shaplakanon.com\/wdc\/php-syntax-and-variables\/","og_site_name":"Web Development Course","article_published_time":"2024-07-13T19:12:09+00:00","article_modified_time":"2024-07-13T19:12:10+00:00","author":"ShaplaKanon","twitter_card":"summary_large_image","twitter_misc":{"Written by":"ShaplaKanon","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/shaplakanon.com\/wdc\/php-syntax-and-variables\/#article","isPartOf":{"@id":"https:\/\/shaplakanon.com\/wdc\/php-syntax-and-variables\/"},"author":{"name":"ShaplaKanon","@id":"https:\/\/shaplakanon.com\/wdc\/#\/schema\/person\/f5f224239283c27426dadc2e4cc9a825"},"headline":"PHP syntax and variables","datePublished":"2024-07-13T19:12:09+00:00","dateModified":"2024-07-13T19:12:10+00:00","mainEntityOfPage":{"@id":"https:\/\/shaplakanon.com\/wdc\/php-syntax-and-variables\/"},"wordCount":330,"commentCount":0,"articleSection":["PHP"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/shaplakanon.com\/wdc\/php-syntax-and-variables\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/shaplakanon.com\/wdc\/php-syntax-and-variables\/","url":"https:\/\/shaplakanon.com\/wdc\/php-syntax-and-variables\/","name":"PHP syntax and variables - Web Development Course","isPartOf":{"@id":"https:\/\/shaplakanon.com\/wdc\/#website"},"datePublished":"2024-07-13T19:12:09+00:00","dateModified":"2024-07-13T19:12:10+00:00","author":{"@id":"https:\/\/shaplakanon.com\/wdc\/#\/schema\/person\/f5f224239283c27426dadc2e4cc9a825"},"breadcrumb":{"@id":"https:\/\/shaplakanon.com\/wdc\/php-syntax-and-variables\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/shaplakanon.com\/wdc\/php-syntax-and-variables\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/shaplakanon.com\/wdc\/php-syntax-and-variables\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/shaplakanon.com\/wdc\/"},{"@type":"ListItem","position":2,"name":"PHP syntax and variables"}]},{"@type":"WebSite","@id":"https:\/\/shaplakanon.com\/wdc\/#website","url":"https:\/\/shaplakanon.com\/wdc\/","name":"Web Development Course","description":"Become a Web Developer from Home","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/shaplakanon.com\/wdc\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/shaplakanon.com\/wdc\/#\/schema\/person\/f5f224239283c27426dadc2e4cc9a825","name":"ShaplaKanon","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/ef2c8f93a0558c2047555f674c8746b22988ace93eba9262d198d0a28236ce97?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/ef2c8f93a0558c2047555f674c8746b22988ace93eba9262d198d0a28236ce97?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/ef2c8f93a0558c2047555f674c8746b22988ace93eba9262d198d0a28236ce97?s=96&d=mm&r=g","caption":"ShaplaKanon"},"sameAs":["https:\/\/shaplakanon.com\/wdc\/"],"url":"https:\/\/shaplakanon.com\/wdc\/author\/sabahat\/"}]}},"_links":{"self":[{"href":"https:\/\/shaplakanon.com\/wdc\/wp-json\/wp\/v2\/posts\/65","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/shaplakanon.com\/wdc\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/shaplakanon.com\/wdc\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/shaplakanon.com\/wdc\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/shaplakanon.com\/wdc\/wp-json\/wp\/v2\/comments?post=65"}],"version-history":[{"count":1,"href":"https:\/\/shaplakanon.com\/wdc\/wp-json\/wp\/v2\/posts\/65\/revisions"}],"predecessor-version":[{"id":66,"href":"https:\/\/shaplakanon.com\/wdc\/wp-json\/wp\/v2\/posts\/65\/revisions\/66"}],"wp:attachment":[{"href":"https:\/\/shaplakanon.com\/wdc\/wp-json\/wp\/v2\/media?parent=65"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/shaplakanon.com\/wdc\/wp-json\/wp\/v2\/categories?post=65"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/shaplakanon.com\/wdc\/wp-json\/wp\/v2\/tags?post=65"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}