Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Jul 2008
    Location
    Manila, PH
    Posts
    15
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Question Displaying PHP codes without DB yet

    Hi!

    Sorry for the total noob question. I just would like to ask if its possible to view my PHP codes (even just the simple "Hello World" in echo) even if I don't have database yet.

    My PHP codes are inside/saved as .html and as follows:

    PHP Code:
    <html><head><title>Untitled Document</title></head>
    <body>

    <?php 
    /* Turn on error reporting */
    ini_set('display_errors'1);
    ini_set('display_startup_errors'1);
    error_reporting(E_ALL);

    $name "Em";
    $age 19;
    $school "De La Salle University";

    /* Output text using echo */
    echo "Hello World";
    // Output text using print
    print "Hello " $age " years old " $name ".";
    echo 
    "Your name has " strlen($name) . " letters."// Em: length = 2
    echo "The word \"University\" is found at the " strpos($school"University") . " th position." // University: starting position = 12 (because counting starts at 0)
    ?>

    </body>
    </html>

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    You don't need a database to program in PHP. But unless you're host is set up to parse .html files as PHP you won't get any processing either. Rename .html to .php and it should work.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #3
    New Coder
    Join Date
    Jul 2008
    Location
    Manila, PH
    Posts
    15
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Okay, so I now changed the extension from .html to .php. However, if I try to view the .php file, nothing will be displayed in the browser? Do I need to setup something with regards to Apache/MySQL before being able to view my "Hello World"? (^_^);

  • #4
    New Coder
    Join Date
    Jul 2008
    Location
    Indonesia
    Posts
    13
    Thanks
    0
    Thanked 1 Time in 1 Post
    just use XAMPP or WAMP (for Windows)
    and put your code in htdocs (for XAMPP) or www (fror WAMP)

    open ur browser n type http://localhost/path_to_your_file.php

    it should work...
    ... newbie LOVES free ....

  • Users who have thanked kuse50 for this post:

    mpacaon (07-31-2008)

  • #5
    New Coder
    Join Date
    Jul 2008
    Location
    Manila, PH
    Posts
    15
    Thanks
    2
    Thanked 0 Times in 0 Posts
    I tried putting myfile.php inside Apache's htdocs, and restarted the Apache server.
    I went to http://localhost/myfile.php and nothing is displayed.

    I then realized that some parts of the codes are wrong:

    PHP Code:
    $message "Hello";
    $number 143;
    $file fopen("test.txt""w");
    echo 
    vfprintf($file"%s world. Day number %u", array($message$number)); 
    What is actually wrong with these lines of code?

    My editor (Adobe Dreamweaver CS3) won't also able to detect vfprintf as a valid function. Why is that?
    Last edited by mpacaon; 07-31-2008 at 09:31 AM.

  • #6
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    vprintf is the same as printf except it wants an array of parameters. You have given it three arguments, and it only accepts two arguments. You cannot write to a file in this way using PHP, and I don't believe you can override the stdout to pipe it to a file. Instead, use vsprintf/sprintf with you're format and arrays, capture the output in a variable and use fwrite to write the new entry to a file.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •