kayz100 Posted August 2, 2013 Share Posted August 2, 2013 i guys, I have been stuck for a few days now. My PHP programming is much better but stuck a little on a project. How do I get users to input their own website URL into my website so that they can easily be linked to my website. Below is the little code which I am failing to get users to input their own website url. I can use the code if I type in my own website before FTPing the account but that's not what I am looking for: I actually want users to input their own url for example www.mywebsite.com only and this then gets saved onto the database, which I have already, thanks a lot. Please only respond to what I am asking guys. <?php $input= "website is http://www.nameofsite.com"; //the above works fine but i want it empty so users can input their own hyperlinked urls $clickable = preg_replace('*(f|ht)tps?://[A-Za-z0-9\./?=\+&%]+*', '<a href="$0">$input</a>', $input); echo $clickable; ?> <form action="" method="POST">Update your URL<br /> Email: <input type="text" value="php url" name="email"> Website: <input type="text" value="php url" name="website"> <input type="submit" value="submit" name="submit"> </form> Thanks a lot guys Kayz100 Quote Link to comment Share on other sites More sharing options...
PravinS Posted August 2, 2013 Share Posted August 2, 2013 <?php if (isset($_POST['btnsubmit'])) { $input = "website is ".trim($_POST['website']); //the above works fine but i want it empty so users can input their own hyperlinked urls $clickable = preg_replace('*(f|ht)tps?://[A-Za-z0-9\./?=\+&%]+*', '<a href="$0">$input</a>', $input); echo $clickable; } ?> <form action="" method="POST">Update your URL<br /> Email: <input type="text" value="php url" name="email"> Website: <input type="text" value="php url" name="website"> <input type="submit" value="submit" name="btnsubmit"> </form> use above code Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted August 2, 2013 Share Posted August 2, 2013 Note that variables won't work within single quoted strings. <?php ...'<a href="$0">$input</a>'... ?> Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted August 2, 2013 Share Posted August 2, 2013 Also, is the regular expression necessary for creating the link? You could just utilize the URL which is already in a separate variable. <?php $_POST['website'] = trim($_POST['website']); echo "website is <a href='{$_POST['website']}'>{$_POST['website']}</a>"; ?> Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted August 2, 2013 Share Posted August 2, 2013 Sorry, the portion after the code was cut off. Here is the rest: Of course, you'll want to perform some extra tests to make sure the POST variable actually contains a URL. You could utilize the built-in validation filter: http://php.net/manual/en/filter.filters.validate.php Quote Link to comment Share on other sites More sharing options...
kayz100 Posted August 5, 2013 Author Share Posted August 5, 2013 Thanks a lot Pravins, got it working now mate Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.