Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!--Write a PHP program URLReplacer.php that takes a text from a textarea and replaces all URLs with
- the HTML syntax <a href= "…" ></a> with a special forum-style syntax [URL=…][/URL].-->
- <!DOCTYPE html>
- <html>
- <head lang="en">
- <meta charset="UTF-8">
- <title>URL Replacer</title>
- <style type="text/css">
- #container {
- width: 350px;
- }
- </style>
- </head>
- <body>
- <div id="container">
- <form method="post">
- <p><textarea name="text" cols="50" rows="8" placeholder="Enter your text..."
- autofocus required></textarea></p>
- <input type="submit" value="Replace URL"/>
- </form>
- <p>
- <?php
- mb_internal_encoding('UTF-8');
- if (!isset($_POST['text']) || trim($_POST['text']) === '') {
- die('Please, enter some text in the Textfield on Form!!!');
- }
- $text = trim($_POST['text']);
- $text = preg_replace('/<a href=\\"([^\\"]*)\\">(.*)<\/a>/iU', "[URL=$1]$2[/URL]", $text);
- echo htmlspecialchars($text);
- ?>
- </p>
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement