sqc Posted October 15, 2015 Share Posted October 15, 2015 Hello, newbie here. Let’s say this url refers to my page: www.referringpage.com/folder/abc123 (1) I want to capture the "abc123" part that comes after the last forward slash and assign it to a variable named "id" (2) Then I want to create a clickable link: www.mynewlink.com/folder/abc123 Probably pretty simple to the vets. Thanks in advance! Quote Link to comment Share on other sites More sharing options...
scootstah Posted October 15, 2015 Share Posted October 15, 2015 http://php.net/parse_url And then http://php.net/manual/en/function.parse-str.php Quote Link to comment Share on other sites More sharing options...
sqc Posted October 15, 2015 Author Share Posted October 15, 2015 As I mentioned, I know very little php. This is what I tried that didnt work: $url = $_SERVER['HTTP_REFERER']; $id = var_dump(parse_url($url, PHP_URL_PATH)); echo $id; Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted October 15, 2015 Share Posted October 15, 2015 “Didn't work” is a bit vague. <?php $_SERVER['HTTP_REFERER'] = 'https://www.mynewlink.com/folder/abc123'; $url_path = parse_url($_SERVER['HTTP_REFERER'], PHP_URL_PATH); $url_id = basename($url_path); var_dump($url_id); Quote Link to comment Share on other sites More sharing options...
scootstah Posted October 15, 2015 Share Posted October 15, 2015 (edited) First of all, var_dump() doesn't return anything. So your $id will be null. Secondly, parse_url() returns an array not a string. Did you look at the manual? EDIT: Oops sorry, you're using a component flag, so it does return a string. Edited October 15, 2015 by scootstah Quote Link to comment Share on other sites More sharing options...
sqc Posted October 16, 2015 Author Share Posted October 16, 2015 “Didn't work” is a bit vague. <?php $_SERVER['HTTP_REFERER'] = 'https://www.mynewlink.com/folder/abc123'; $url_path = parse_url($_SERVER['HTTP_REFERER'], PHP_URL_PATH); $url_id = basename($url_path); var_dump($url_id); Thanks. this returned: string(6) "abc123" If the actual refering page url was www.referringpage.com/folder/abc123 how would I take what youve done but actually capture the url and then print the clickable link http://www.mynewlink.com/folder/abc123 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.