bronzemonkey Posted September 28, 2007 Share Posted September 28, 2007 If I have links in these formats... 1) http://www.somewebsite.com/IWANTTHIS/ 2) http://www.somewebsite.com/IWANTTHIS/this-is-unwanted-and-variable/ ...and I'd like to extract the IWANTTHIS part (which is not constant) from the permalinks, how do I go about doing this? I'm trying to find a way to achieve context sensitive menus in wordpress and this seems to be the only way to access the page-slug of pages and posts. Thanks for any help. Quote Link to comment https://forums.phpfreaks.com/topic/71098-solved-help-with-extracting-a-specific-part-of-an-url/ Share on other sites More sharing options...
tippy_102 Posted September 29, 2007 Share Posted September 29, 2007 This thread from earlier today should help you out: http://www.phpfreaks.com/forums/index.php/topic,161086.0.html Quote Link to comment https://forums.phpfreaks.com/topic/71098-solved-help-with-extracting-a-specific-part-of-an-url/#findComment-357695 Share on other sites More sharing options...
sasa Posted September 29, 2007 Share Posted September 29, 2007 try <?php $a = 'http://www.somewebsite.com/IWANTTHIS/this-is-unwanted-and-variable/'; $a = explode('/', $a); echo $a[3]; ?> Quote Link to comment https://forums.phpfreaks.com/topic/71098-solved-help-with-extracting-a-specific-part-of-an-url/#findComment-357755 Share on other sites More sharing options...
bronzemonkey Posted September 29, 2007 Author Share Posted September 29, 2007 Thanks, I ended up using the following (in wordpress): <?php $url = get_permalink('', false); // get the permalink $spliturl = explode("/", $url); // break down the permalink $pageID = $spliturl[3]; // select the page slug ?> <body id="body_<?php echo $pageID; ?>"> Quote Link to comment https://forums.phpfreaks.com/topic/71098-solved-help-with-extracting-a-specific-part-of-an-url/#findComment-358079 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.