Showing posts with label php. Show all posts
Showing posts with label php. Show all posts

Thursday, 21 July 2016

How to access local file system in php using XAMPP ?


XAMPP manages a document root folder on local environment : <install-dir>\htdocs

To make a file available through your development server, copy the files in this folder.
 

To access file : <install-dir>\htdocs\test\sample.txt , Use in browser :
http://localhost/test/sample.txt

What is XAMPP and how to use it ?


XAMPP is complete package of Development environment for Php.

 

Download and install XAMPP

It will install the Apache Web server, MySQL etc.

XAMPP comes with a control panel you can use to start and stop Apache.


 


Visit URL into your browser : http://localhost which will display home page of XAMPP.

Tuesday, 19 July 2016

is it possible to execute PHP code from the command line instead of Browser ?


Yes !
Use php command with ./
php ./hello.php

You can use -i flag to generate the result in HTML file.
php -i > /tmp/phpresult.html

How to add comments to php code ?


2 types of comment


<?php
    // This is line comment
    /* This is 
       C-style comment */
    echo 'hello world';
?>

How to use variables in php code ?


For display variables using echo, always use variable in double quotes.

Example
<?php
    $text="Hello world";
    echo '<html><head><title>Title here</title></head><body>'; 

    echo '$text<br>';
    echo "$text<br>";
    echo '</body></html>';
?>


Output
$text
Hello world

How to write program in PhP ?


Hello World in PhP

Example
<html>
 <head>
    <title>PHP Test</title>
 </head>
 <body>
    <?php echo '<p>Hello World</p>'; ?>
  </body>
</html>






3 ways to use PhP code in your php file 
<?
  echo 'hello world 1<br>';
?>
 

<script language="php">
  echo 'hello world 2<br>';

</script>
 

<%
  echo 'hello world 3<br>';
%>



Example 2
<?php
    echo '<html>
         <head>
         <title>Title of the site</title> '.
         '</head>';


    echo "<body>hello world<br></body></html>\n";
?>