Advertisement
dimipan80

URL Replacer

Apr 24th, 2015
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.98 KB | None | 0 0
  1. <!--Write a PHP program URLReplacer.php that takes a text from a textarea and replaces all URLs with
  2. the HTML syntax <a href= "…" ></a> with a special forum-style syntax [URL=…][/URL].-->
  3.  
  4. <!DOCTYPE html>
  5. <html>
  6. <head lang="en">
  7.     <meta charset="UTF-8">
  8.     <title>URL Replacer</title>
  9.     <style type="text/css">
  10.         #container {
  11.             width: 350px;
  12.         }
  13.     </style>
  14. </head>
  15. <body>
  16. <div id="container">
  17.     <form method="post">
  18.         <p><textarea name="text" cols="50" rows="8" placeholder="Enter your text..."
  19.                      autofocus required></textarea></p>
  20.         <input type="submit" value="Replace URL"/>
  21.     </form>
  22.     <p>
  23.         <?php
  24.         mb_internal_encoding('UTF-8');
  25.  
  26.         if (!isset($_POST['text']) || trim($_POST['text']) === '') {
  27.             die('Please, enter some text in the Textfield on Form!!!');
  28.         }
  29.  
  30.         $text = trim($_POST['text']);
  31.         $text = preg_replace('/<a href=\\"([^\\"]*)\\">(.*)<\/a>/iU', "[URL=$1]$2[/URL]", $text);
  32.  
  33.         echo htmlspecialchars($text);
  34.         ?>
  35.     </p>
  36. </div>
  37. </body>
  38. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement