Code:
<?php
$sub = $_POST['submit'];
if($sub == 'submit') {
$url = trim($_POST['url']);
if($url == '') {
echo "<script> alert('Please enter a valid URL to proceed');</script>";
}
}
?>
<html>
<head>
<title>URL Experiment</title>
</head>
<body>
<form name="f1" action="" method="post">
URL: <input type="text" name="url">
<br>
<input type="submit" name="submit" value="submit">
</form>
<br>
<?php
if($url != '') {
echo "<a href=\"$url\" target=\"_blank\">$url</a>";
}
?>
</body>
</html>
You can achieve whatever you want using the above code snippet.

Originally Posted by
VatsaL
Also, is it possible to have the same function on an .htm file??
It is not possible for you to execute a PHP function from a file whose extension is .htm or .html.
If you want to perform something using PHP then the file extension must be .php. You can insert all the html tags in a PHP file.

Originally Posted by
VatsaL
How should I set up the php page?
1. You can't open a PHP page by double clicking on it like an HTML page
2. I would suggest to use XAMPP. Because the package has Apache webserver, MySQL Database Package, etc as a single installer.
3. You can install them by clicking some two three buttons which is definitely a lot simpler than invidual installation of web server, PHP, etc
4. After the installation of XAMPP (assuming that u r using Windows) you can save your php files inside C:\program files\xampp\htdocs folder which is the default web publishing directory.
5. To view your php file which is in the above mentioned folder open your browser and type http://localhost/thefilename.php
*thefilename.php can be anything you want
*the localhost can be replaced by your machine name
Hope this will help you to start the PHP script running
Bookmarks