{"id":50,"date":"2026-05-20T07:09:18","date_gmt":"2026-05-20T07:09:18","guid":{"rendered":"https:\/\/gigz.pk\/php\/?post_type=lesson&#038;p=50"},"modified":"2026-05-21T14:36:54","modified_gmt":"2026-05-21T14:36:54","slug":"writing-first-php-program","status":"publish","type":"lesson","link":"https:\/\/gigz.pk\/php\/?lesson=writing-first-php-program","title":{"rendered":"Writing First PHP Program"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Introduction<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Writing your first PHP program is the starting point of learning server side web development. PHP allows you to create dynamic web pages that run on the server and display output in the browser. A simple first program helps you understand PHP syntax, structure, and execution flow.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Understanding PHP File Structure<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A PHP file is saved with the extension .php. It can contain both HTML and PHP code. PHP code is written inside special tags that tell the server to process it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Basic PHP Syntax<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">PHP code always starts with PHP opening tag and ends with closing tag. Inside these tags, you write instructions that the server executes.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Writing Your First PHP Program<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To create your first program, follow these steps:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Create a new file and save it as index.php<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Write the following code:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">php &lt;?php echo Hello World ?&gt;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Run the file on a local server such as XAMPP or WAMP. Open your browser and go to localhost to see the output.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Expected Output<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Hello World<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">How PHP Code Works<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">When you open a PHP file in the browser, the server processes the PHP code first. It converts it into plain HTML and sends the result to the browser. The browser only shows output, not the PHP code.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Key Points for Beginners<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">PHP code must be written inside PHP tags<br>Every statement ends with a semicolon<br>echo is used to display output on the screen<br>PHP runs on the server, not in the browser<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Common Mistakes to Avoid<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Forgetting semicolons at the end of statements<br>Not saving file with .php extension<br>Running file without local server setup<br>Typing incorrect syntax in echo statement<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Practical Exercise<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Create a PHP file and display your name using echo statement<br>Modify the program to show your city and country<br>Run the file in browser using localhost server<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Career Importance<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Learning how to write your first PHP program builds the foundation for backend development. It helps you understand how dynamic websites work and prepares you for advanced PHP topics like forms, databases, and frameworks.<\/p>\n\n\n<div class=\"yoast-breadcrumbs\"><span><span><a href=\"https:\/\/gigz.pk\/php\">Home<\/a><\/span> \u00bb <span class=\"breadcrumb_last\" aria-current=\"page\">PHP Fundamentals (Beginner Level) > Introduction to PHP > Writing First PHP Program<\/span><\/span><\/div>\n\n\n<div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1779260966950\"><strong class=\"schema-faq-question\"><\/strong> <p class=\"schema-faq-answer\"><\/p> <\/div> <\/div>\n","protected":false},"menu_order":5,"template":"","class_list":["post-50","lesson","type-lesson","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Writing First PHP Program - Learn PHP with GiGz.PK<\/title>\n<meta name=\"description\" content=\"Learn how to write your first PHP program step by step with easy examples, syntax guide, and beginner friendly explanation.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/gigz.pk\/php\/?lesson=writing-first-php-program\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Writing First PHP Program - Learn PHP with GiGz.PK\" \/>\n<meta property=\"og:description\" content=\"Learn how to write your first PHP program step by step with easy examples, syntax guide, and beginner friendly explanation.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/gigz.pk\/php\/?lesson=writing-first-php-program\" \/>\n<meta property=\"og:site_name\" content=\"Learn PHP with GiGz.PK\" \/>\n<meta property=\"article:modified_time\" content=\"2026-05-21T14:36:54+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":[\"WebPage\",\"FAQPage\"],\"@id\":\"https:\\\/\\\/gigz.pk\\\/php\\\/?lesson=writing-first-php-program\",\"url\":\"https:\\\/\\\/gigz.pk\\\/php\\\/?lesson=writing-first-php-program\",\"name\":\"Writing First PHP Program - Learn PHP with GiGz.PK\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/php\\\/#website\"},\"datePublished\":\"2026-05-20T07:09:18+00:00\",\"dateModified\":\"2026-05-21T14:36:54+00:00\",\"description\":\"Learn how to write your first PHP program step by step with easy examples, syntax guide, and beginner friendly explanation.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/php\\\/?lesson=writing-first-php-program#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/gigz.pk\\\/php\\\/?lesson=writing-first-php-program\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/php\\\/?lesson=writing-first-php-program#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/gigz.pk\\\/php\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"PHP Fundamentals (Beginner Level) > Introduction to PHP > Writing First PHP Program\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/php\\\/#website\",\"url\":\"https:\\\/\\\/gigz.pk\\\/php\\\/\",\"name\":\"Learn PHP with GiGz.PK\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/gigz.pk\\\/php\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Writing First PHP Program - Learn PHP with GiGz.PK","description":"Learn how to write your first PHP program step by step with easy examples, syntax guide, and beginner friendly explanation.","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:\/\/gigz.pk\/php\/?lesson=writing-first-php-program","og_locale":"en_US","og_type":"article","og_title":"Writing First PHP Program - Learn PHP with GiGz.PK","og_description":"Learn how to write your first PHP program step by step with easy examples, syntax guide, and beginner friendly explanation.","og_url":"https:\/\/gigz.pk\/php\/?lesson=writing-first-php-program","og_site_name":"Learn PHP with GiGz.PK","article_modified_time":"2026-05-21T14:36:54+00:00","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":["WebPage","FAQPage"],"@id":"https:\/\/gigz.pk\/php\/?lesson=writing-first-php-program","url":"https:\/\/gigz.pk\/php\/?lesson=writing-first-php-program","name":"Writing First PHP Program - Learn PHP with GiGz.PK","isPartOf":{"@id":"https:\/\/gigz.pk\/php\/#website"},"datePublished":"2026-05-20T07:09:18+00:00","dateModified":"2026-05-21T14:36:54+00:00","description":"Learn how to write your first PHP program step by step with easy examples, syntax guide, and beginner friendly explanation.","breadcrumb":{"@id":"https:\/\/gigz.pk\/php\/?lesson=writing-first-php-program#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/gigz.pk\/php\/?lesson=writing-first-php-program"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/gigz.pk\/php\/?lesson=writing-first-php-program#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/gigz.pk\/php"},{"@type":"ListItem","position":2,"name":"PHP Fundamentals (Beginner Level) > Introduction to PHP > Writing First PHP Program"}]},{"@type":"WebSite","@id":"https:\/\/gigz.pk\/php\/#website","url":"https:\/\/gigz.pk\/php\/","name":"Learn PHP with GiGz.PK","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/gigz.pk\/php\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/gigz.pk\/php\/index.php?rest_route=\/wp\/v2\/lesson\/50","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gigz.pk\/php\/index.php?rest_route=\/wp\/v2\/lesson"}],"about":[{"href":"https:\/\/gigz.pk\/php\/index.php?rest_route=\/wp\/v2\/types\/lesson"}],"wp:attachment":[{"href":"https:\/\/gigz.pk\/php\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=50"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}