Q:

Pagination URL encoding

I have some modules on a site that basically functions as ORMs and one as a search engine for those ORMs. The problem I'm currently running into is that when a search term is submitted, it gets double urlencoded, and looks like this:
submitted term: "Boston +New"
encoded url: "site.com/search/Boston%2B%252BNew"

and this is correct, and allows me to safely pass these terms through a giant search module. It also allows me to decode one step safely in the module and do searches in BOOLEAN MODE so users can use a few specials affect characters (the + in front of New puts extra weight on that word being in the match-against).
This is all fine. However, using EE's standard pagination tool, it outputs the url links in this manner:
pagination_url: "site.com/search/Boston+%2BNew/P20"

so when you go to any other page, the search term isn't what you searched for. I'm looking for a simpler solution than using regex to pull apart the pagination_url, mangle it, and put it back together. Is there a way to get just the pagination top segment (ie, P10, P20)? Then I can just put the url together with the segment var, ie
site.com/search/{segment_2}/{page_path}

Or any other suggestions?

A:

I really couldn't find a good answer anywhere, so I'm putting this here for anyone else who runs into this problem. First, you need to make sure your template has PHP allowed on Output. Next, dump this little function somewhere in your template:
<?php
// fun, thanks expression engine!
function pager($in)
{
    $a = array();
    preg_match('/(P\d+)/', $in, $a);
    if(isset($a[0]))
    {
        return $a[0];
    }
}
?>

Then, instead of just dumping {pagination_url} into an anchor link, my pagination links looked like this:
{previous_page}
    <a href="{site_index}/search/<?=urlencode('{segment_2}')?>/<?=pager('{pagination_url}')?>" class="page-previous">
        &larr;
    </a>
{/previous_page}

But yeah, that's how I went about it. It's not clean perfect, but it works for anyone who has to paginate a MySQL query using keywords and match-against.

