我想從URL字符串中返回頁面標識。如何在字符串匹配後返回部分PHP字符串?
例如,如果我有這樣的:
<?php
$string = "foobar.com/?page_id=20"; // <-dynamically generated
$new_string = some_function($string, get stuff after 'page_id='); // (need to know what function to use and how)
// I want to get this:
echo $new_string; //($new_string = "20";)
?>
///更新!
我正試圖添加一個類到鏈接,如果我目前在該頁面或其子項之一。以下是我的了:
<?php
$items = wp_get_nav_menu_items("navigation");
$counter = 1;
foreach($items as $item): ?>
<a id="mainnav<?php echo $counter; ?>" class="
<?php
//home
$theurl = $item->url;
$new_string = modify_withfunction("after page_id=", $theurl);
if ($new_string == $page->post_parent || $new_string == $page->ID) {
echo 'currentnav';
}
?>
" href="<?php echo $item->url; ?>"><?php echo $item->title; ?></a>
<?php
$counter++;
endforeach;
?>
是不是可以只使用$ _GET超全局? – helloandre 2011-03-22 00:28:09
是的,但我沒有測試當前頁面。我正在測試返回的網址。 – Dave 2011-03-22 00:29:03