make a text as url to another text

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tanares
Forum Newbie
Posts: 2
Joined: Mon Oct 17, 2011 3:34 pm

make a text as url to another text

Post by tanares »

i want to take from user two texts
the second one (will be url), i want to make it as url to the first text.
can you help me, how can i do it with php
maxx99
Forum Contributor
Posts: 142
Joined: Mon Nov 21, 2011 3:40 am

Re: make a text as url to another text

Post by maxx99 »

Could you provide an example of 2 inputs and 2 outputs?
mikeashfield
Forum Contributor
Posts: 159
Joined: Sat Oct 22, 2011 10:50 am

Re: make a text as url to another text

Post by mikeashfield »

I think you mean a link generator right? The form:

Code: Select all

<html>
<body>
<form action="/createURL.php" method="POST">
<input type="text" name="URLtitle"></br>
<input type="text" name="URLlink"></br>
<input type="submit" name="submit" value="Make URL">
</form>
</body>
</html>
And, the PHP file:

Code: Select all

<?php
    if (isset($_POST['URLtitle']) && isset($_POST['URLlink'])) {
        $URLlink=$_POST['URLlink'];
        $URLtitle=$_POST['URLtitle'];
        if (preg_match('((mailto\:|(news|(ht|f)tp(s?))\://){1}\S+)', $URLlink)) {
            echo "<a href='".$URLlink."'>".$URLtitle."</a>";
            }
        }
?>
Post Reply