Thursday 15 March 2012

PHP, Delete parts of a URL variable -


इस सवाल का पहले से ही एक उत्तर है: < / P>

  • 17 उत्तरों

    मेरे पास निम्न php चर है

      $ currentUrl   

    यह PHP चर मुझे वर्तमान यूआरएल पृष्ठ देता है। उदाहरण के लिए: यह देता है:

      http://example.com/test-category/page.html?_ore=norn&___frore=norian   

    मैं किस पीएचपी कोड का उपयोग कर सकता हूं जो इस यूआरएल लिंक को " .html " के बाद सब कुछ हटा देगा और मुझे एक साफ यूआरएल लिंक लौटाएगा, उदाहरण के लिए:

      http : //example.com/test-category/page.html   

    यह एक नया चर $ clean_currentUrl में वापस किया जाएगा

    ऐसा कुछ:

      & lt; php $ currentUrl = 'http://example.com /test-category/page.html?_ore=norn&___frore=norian '; Preg_match ('~ http: \ / \ /.*। Html ~', $ currentUrl, $ मैचों); print_r ($ से मेल खाता है);   

    नीचे amigura की टिप्पणी देखें। उस केस को संभालने के लिए regex बदलें:

      & lt;? Php $ currentUrl = 'http://example.com/test-category/page.html?_ore=norn&___frore=norian' ; Preg_match ('~ (http: \ / \ /.* \ .. +) \? ~, $ CurrentUrl, $ मैचों); print_r ($ से मेल खाता है);    

No comments:

Post a Comment