CUTCODEDOWN
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 212 times)

GrumpyYoungMan

  • Hero Member
  • *****
  • Posts: 776
  • Karma: +8/-0
    • Grumpy Young Man
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]
https://myURL/some/path/to/page/2/

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(
        $path,
        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: 1029
  • Karma: +188/-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.
We are all, we are all, we are all FRIENDS! For today we're all brothers, tonight we're all friends. Our moment of peace in a war that never ends.

 

SMF spam blocked by CleanTalk

Advertisement