Videos
I'm new to php and I need to test my code but i do not know how i would be able to do that its not like what I'm used to PowerShell has to be the easiest one to test on a local system. but i apricate the help.
There's no need for a server if using PHP 5.5+ - it has a built-in server (http://www.php.net/manual/en/features.commandline.webserver.php)
Just use:
$ cd ~/public_html
$ php -S localhost:8000
As a minimalistic solution, on the command line you can also start php in interactive shell with php -a that will execute the commands you enter line by line. I often use it for testing small snippets of code.
Congratulations on getting started with php. You will need a web server to run PHP. Firefox can process HTML, CSS and Javascript markup/codes to output the web page but it can't process. It's a server side language and you will need some sort of server to do that.
If you have a Windows PC, the easiest way, at least for me, would be XAMPP/WAMP or similar software. You can find a good comparison chart in Wikipedia.
You can make the code clean with following syntax.
<html>
<head>
<title>PHP Test</title>
</head>
<body>
<p><?php echo 'Hello World'; ?></p>
</body>
</html>
looks neat I think :)
Firefox is not able to interpret PHP code by itself. You will have to setup a local web server to run your code, and produce HTML, which could be read by Firefox.
To view the file you uploaded, browse: site.com/wp-content/mytest.php
If you just type site.com/mytest , wordpress will thin you are reffering to a page stored in the wp-database. Since it's not you cant view it.
To add the page in the menu, use custom menu and add as "Custom link".
You can make your page a wp custom page template by adding this at the top:
Copy/*
Template Name:Your Page Name
*/
Then create a page in the wordpress dashboard pages and select your page template from the page template dropdown.
You can use $_SERVER['REQUEST_URI'], $_SERVER['PHP_SELF'], or __FILE__ depending on your version of PHP and how you have your code setup. If you are in a framework it may have a much more developer-friendly function available. For example, CodeIgniter has a function called current_url()
Per PHP Docs:
$_SERVER['REQUEST_URI']: The URI which was given in order to access this page; for instance, '/index.html'.
$_SERVER['PHP_SELF']: The filename of the currently executing script, relative to the document root. For instance, $_SERVER['PHP_SELF'] in a script at the address http://example.com/test.php/foo.bar would be /test.php/foo.bar. The __ FILE__ constant contains the full path and filename of the current (i.e. included) file. If PHP is running as a command-line processor this variable contains the script name since PHP 4.3.0. Previously it was not available.
<?php
$url = $_SERVER["REQUEST_URI"];
$pos = strrpos($url, "hello.php");
if($pos != false) {
echo "found it at " . $pos;
}
?>
http://www.php.net/manual/en/reserved.variables.server.php
http://php.net/manual/en/function.strrpos.php