Yehonatan

Untitled

Oct 10th, 2012
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.60 KB | None | 0 0
  1. <?php
  2.  
  3.     $url = $_GET['url'];
  4.  
  5.     $rules = array(array('/article\/([0-9])/', '/articles/show/$1'));
  6.  
  7.     $i = 0;
  8.         $found = false;
  9.     //We check if we haven't found any rule that matches to what we want and that we haven't went beyond the array index
  10.         while(!$found && !empty($rules) && $i < count($rules))
  11.           {
  12.              if(preg_match($rules[$i][0], $url))
  13.                 {
  14.                   $url = preg_replace($rules[$i][0], $rules[$i][1], $url);
  15.                    $found == true;
  16.                    }
  17.                 $i++;
  18.            }
  19.  
  20.     //....Do what you want with the url
Advertisement
Add Comment
Please, Sign In to add comment