24 lut 2016

Parsowanie adresu uri strony

$urls = array (
'http://kody.wig.pl/file.php?key=9emixire&ampexpires=1456358400&signature=76f289',
'http://kody.wig.pl/file.php?key=9emixire&expires=1456358400&signature=76f289');
$arr_url = parse_url($urls[0]);
parse_str($arr_url['query'], $arr_query);
print_r($arr_url);
print_r($arr_query);

Wynik:

Array
(
[scheme] => http
[host] => kody.wig.pl
[path] => /file.php
[query] => key=9emixire&expires=1456358400&signature=76f289
)
Array
(
[key] => 9emixire
[expires] => 1456358400
[signature] => 76f289
)
24 lut 2016

Obliczenie statystyk przy wykorzystaniu regexp_replace

select
  regexp_replace(
    url,
    E'^http:\/\/.*\/(.*)-(\\d+).html(\\?)?(.*)?',
    E'\\1'
  ) as t_name,
  regexp_replace(url, E'^.*-(\\d+).html(\\?)?(.*)?', E'\\1') :: integer as t_id,
  count(*) as t_cnt
from unnest(
    ARRAY [
'http://kody.wig.pl/ustawienie_wartosci_pol_input_w_formularzu_strony-15.html',
'http://kody.wig.pl/ustawienie_wartosci_pol_input_w_formularzu_strony-15.html?
action=test&value1=118-115&value2=119-116'
]
  ) as t(url)
group by
  t_name,
  t_id

Wynik:

"ustawienie_wartosci_pol_input_w_formularzu_strony";15;2