записать часть значения url в переменную

Discussion in 'PHP' started by ufaclub, 5 Dec 2011.

  1. ufaclub

    ufaclub New Member

    Joined:
    13 Jul 2010
    Messages:
    204
    Likes Received:
    0
    Reputations:
    0
    PHP:
    $thispage $_SERVER['REQUEST_URI'];
    получаем ссылки вида

    http://site.ru/index.php?option=com_content&id=119&task=view

    или

    http://site.ru/index.php?option=com_virtuemart&category_id=14&page=shop.browse

    вот как мне это значение 119, или 14 записать в переменую $id
     
  2. KeepInTouch

    KeepInTouch New Member

    Joined:
    14 Oct 2011
    Messages:
    2
    Likes Received:
    0
    Reputations:
    0
    Регуляркой можно:
    PHP:
    $thispage $_SERVER['REQUEST_URI'];
    preg_match("/id=(\d+)/i"$thispage$m); 
    $id $m[1];
     
  3. krypt3r

    krypt3r Elder - Старейшина

    Joined:
    27 Apr 2007
    Messages:
    1,507
    Likes Received:
    389
    Reputations:
    101
    parse_url() / parse_str()
     
    #3 krypt3r, 5 Dec 2011
    Last edited: 5 Dec 2011
  4. daniel777

    daniel777 Elder - Старейшина

    Joined:
    8 Jul 2010
    Messages:
    517
    Likes Received:
    90
    Reputations:
    37
    А не проще ли так?

    $id = $_GET['id'];
     
  5. Чакэ

    Чакэ Elder - Старейшина

    Joined:
    15 Aug 2010
    Messages:
    260
    Likes Received:
    66
    Reputations:
    62
    настоящий программист не ищет лёгких путей.
     
    1 person likes this.