I have this script that updates a txt file with a website link. I want the script to omit the http:// and www. when the user enters them. How can I do that please. Here is the code I have so far. <?php $website = empty($_GET["name"]) ? "" : $_GET["name"]; if(!$name){$message1 = "Please enter a Website name.";} ?> <html> <head> <style> .tdr{text-align:right;} </style> </head> <body> <form action="store_it.php" method="post"> <table> <tr> <td class="tdr">Website:</td> <td><input type="text" name="name" value="<?php echo $website; ?>"></td> <td> <?php echo $message1; ?></td> </tr> <tr> <td colspan="3" align="center"><input type="submit" value="Submit"></td> </body> </html> PHP:
<?php $message1 = ''; if (!empty($_GET["name"])) { $name = str_ireplace(array('http://', 'www.'), '', $_GET['name']); } else { $message1 = 'Please enter a Website name.'; } ?> <html> <head> <style> .tdr{text-align:right;} </style> </head> <body> <form action="store_it.php" method="post"> <table> <tr> <td class="tdr">Website:</td> <td><input type="text" name="name" value="<?php echo $website; ?>"></td> <td> <?php echo $message1; ?></td> </tr> <tr> <td colspan="3" align="center"><input type="submit" value="Submit"></td> </body> </html> PHP:
I'm sorry it's not working Just to tell you more about the script. There are 3 files index.php, store_it.php, and domains.txt the file index.php is the one that collects the website URL, then store_it.php stores it inside the file domains.txt. Please help. Thank you
Hello, Try this <?php $message1 = ''; if (!empty($_GET["name"])) { $website = str_ireplace(array('http://', 'www.'), '', $_GET['name']); } else { $message1 = 'Please enter a Website name.'; } ?> <html> <head> <style> .tdr{text-align:right;} </style> </head> <body> <form action="store_it.php" method="post"> <table> <tr> <td class="tdr">Website:</td> <td><input type="text" name="name" value="<?php echo $website; ?>"></td> <td> <?php echo $message1; ?></td> </tr> <tr> <td colspan="3" align="center"><input type="submit" value="Submit"></td> </body> </html>
Still not working Here is the store_it.php file in case you need to check it out: <?php $website = empty($_POST["name"]) ? "" : $_POST["name"]; if(!$website){header("location:index.php?name=$website");} else { $file = "domains.txt"; $a = fopen($file, "a"); fwrite($a,$website."\r\n"); fclose($a); $a = fopen($file, "r"); echo "<table border='1'>"; echo "<tr><th>Website Name</th></tr>"; while(!feof($a)) { echo "<tr><td>".fgets($a)."</td></tr>"; } echo "</table>"; fclose($a); } ?> <form action="index.php"> <input type="submit" value="Add another"> </form> PHP:
PHP code <?php $website = empty($_POST["name"]) ? "" : $_POST["name"]; $website = str_ireplace(array('http://', 'www.'), '', $website); if(!$website){header("location:index.php?name=$website");} else { $file = "domains.txt"; $a = fopen($file, "a"); fwrite($a,$website."\r\n"); fclose($a); $a = fopen($file, "r"); echo "<table border='1'>"; echo "<tr><th>Website Name</th></tr>"; while(!feof($a)) { echo "<tr><td>".fgets($a)."</td></tr>"; } echo "</table>"; fclose($a); } ?> <form action="index.php"> <input type="submit" value="Add another"> </form>
This is what I'm getting now: Fatal error: Call to undefined function: str_ireplace() in /homepages/40/d153471067/htdocs/website.com/Alexa/Script/store_it.php on line 3 Please help
Fatal error: Call to undefined function: str_ireplace() in /homepages/40/d153471067/htdocs/website.com/Alexa/Script/store_it.php on line 3
Replace your code with below code <?php $website = empty($_POST["name"]) ? "" : $_POST["name"]; $website = str_replace(array('http://', 'www.'), '', $website); if(!$website){header("location:index.php?name=$website");} else { $file = "domains.txt"; $a = fopen($file, "a"); fwrite($a,$website."\r\n"); fclose($a); $a = fopen($file, "r"); echo "<table border='1'>"; echo "<tr><th>Website Name</th></tr>"; while(!feof($a)) { echo "<tr><td>".fgets($a)."</td></tr>"; } echo "</table>"; fclose($a); } ?> <form action="index.php"> <input type="submit" value="Add another"> </form>
You look like a great Coder. We will be honored to have you join our list of coders on our website jobsinnorthofamerica.com/freelance Once again thank you so much.