Minimalist Semantic Markup

Welcome Guest
Please Login or Register

If you have registered but not recieved your activation e-mail in a reasonable amount of time, or have issues with using the registration form, please use our Contact Form for assistance. Include both your username and the e-mail you tried to register with.

Author Topic: Simplification? Maybe possible?  (Read 137 times)


  • Hero Member
  • *****
  • Posts: 704
  • Karma: +8/-0
    • GrumpyYoungMan
Simplification? Maybe possible?
« on: 3 May 2023, 09:34:58 am »
Code: [Select]
     // Initial Page Setup:
    $page = (!array_key_exists('page', array_flip(REQUEST)) ? 1 : REQUEST[array_search('page', array_keys(array_flip(REQUEST)))+1] );

    $pageSetup = [
        'previous' => $page-1,
        'current' => $page,
        'next' => $page+1,
        'start' => ($page-1) * resultsPerPage,

Trying to get the page number from a url formatted as:
Code: [Select]

I am searching the array for the 'page' array position so I don't have to always rely on the position of the request.

REQUEST is coming from Jason's function:
Code: [Select]
(function() {
    $path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
    if (strpos($path, '..')) die('Hacking Attempt Detected, Aborting');
    $path = str_replace(['\\', '%5C'], '/', substr(
        strlen(pathinfo($_SERVER['SCRIPT_NAME'], PATHINFO_DIRNAME))

    if (empty($path))
        define('REQUEST', [ 'index' ]);
    else {
        $path = explode('/', $path);
        foreach ($path as &$p) $p = urldecode($p);
        define('REQUEST', $path);
Trying to learn a new trick to prove old dogs can learn new ones...

Total Novice have-a go Amateur Programmer - not sure that is the right thing to say... but trying to learn...

Jason Knight

  • Administrator
  • Hero Member
  • *****
  • Posts: 919
  • Karma: +171/-1
    • CutCodeDown -- Minimalist Semantic Markup
Re: Simplification? Maybe possible?
« Reply #1 on: 5 May 2023, 03:12:25 pm »
Not understanding at ALL what you're trying to do with that array, much less why you'd flip it.
I'll fix every flaw, I'll break every law, I'll tear up the rulebook if that's what it takes. You will see, I will crush this cold machine.


SMF spam blocked by CleanTalk