Cherry83

07. URL Replacer v.2

Feb 4th, 2017
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.83 KB | None | 0 0
  1. <?php
  2.  
  3. $input = trim(fgets(STDIN));
  4. $new = '';
  5.  
  6. function replace()
  7. {
  8.     global $input, $new;
  9.  
  10.     $new .= substr($input, 0, strpos($input, '<a'));
  11.     $input = substr($input, strpos($input, 'href') + 4);
  12.     $p = 0;
  13.     while (true) {
  14.         if (in_array($input[$p], array("'", '"'))) {
  15.             $quote = $input[$p];
  16.             break;
  17.         }
  18.         $p++;
  19.     }
  20.     $input = substr($input, $p + 1);
  21.     $i = strpos($input, $quote);
  22.     $new .= "[URL=" . substr($input, 0, $i) . "]";
  23.     $input = substr($input, $i + 1);
  24.     $i = strpos($input, '>');
  25.     $p = strpos($input, '</a');
  26.     $new .= substr($input, $i + 1, $p - $i - 1) . "[/URL]";
  27.     $input = substr($input, $p + 1);
  28.     $input = substr($input, strpos($input, '>') + 1);
  29. }
  30.  
  31. while (strpos($input, 'href') > -1)
  32.     replace();
  33. echo $new . $input;
Advertisement
Add Comment
Please, Sign In to add comment