One problem I see is that you have variables in your functions which will be local in scope only to those functions, but it appears you are expecting to be globally scoped (accessible anywhere). For instance, in the Displaystories() function you reference the $pattern variable, but it is not defined anywhere in that function. While it is defined in an earlier function, it will only be "known" by that earlier function. (The exception to this is the "super-global" arrays such as $_POST, which are "known" everywhere within a PHP script). The typical solution is to pass such variables into the function as a function parameter, e.g.:
// do something with $pattern
// call the function:
$pattern = '/foo*/';
// it doesn't even have to be the same name:
$myRegExpToBeUsed = '/^\s?\d+$/';
PS: Proper and consistent indenting of your code can make it easier for you and us to debug. (Any decent code editor can make indenting easier.) Also, you might want to add these lines during development to make sure you're seeing everything that PHP has to complain about (though you likely wouldn't want it in your production version):
// rest of code...