php - Get a certain part of a changing string -
i have this:
"https://example.com:443/commonauth/?sessiondatakey=2aeeaf42-83d8-4b90-b8b4-39c1856c7de2&type=oauth2" now want string sessiondatakey.
 how extract part string if length of string different every time?
if want sessiondatakey string can way
<?php     $string = "https://example.com:443/commonauth/?sessiondatakey=2aeeaf42-83d8-4b90-b8b4-39c1856c7de2";      preg_match("/sessiondatakey=([a-z0-9\-]*)(&|$)/", $string, $result);      echo $result[1]; ([a-z0-9-]+) - match 1 or more characters a-z, numbers 0-9 , dash
(&|$) - after previous match comes character & or end of string
if want sessiondatakey url can way
<?php     $sessiondatakey = $_get['sessiondatakey'];      echo $sessiondatakey; this classic way of getting parameters url. more here.
Comments
Post a Comment