Untested in PHP.
PHP Code:$url = preg_replace('/' . $domain . '.*?\/(.*)\/', $domain . '/$1/', $current_page);
Untested in PHP.
PHP Code:$url = preg_replace('/' . $domain . '.*?\/(.*)\/', $domain . '/$1/', $current_page);
Corrections to my coding/thoughts welcome.
i have tried it,
function.preg-replace ]: Unknown modifier '/'
:'(
///////////////////////////////////////////////////
///// http://www.mediatutorial.web.id
///////////////////////////////////////////////////
Try this:
PHP Code:$url = str_replace("index.php", "", $url);
$url = str_replace("//", "/", $url);
- Josh
Opps, forgot to close the last one
That should do it.PHP Code:$url = preg_replace('/' . $domain . '.*?\/(.*)\//', $domain . '/$1/', $current_page);
Corrections to my coding/thoughts welcome.
I am terrible with functions, but try this:
Jshor, what you propose would also turnCode:<?php $url="http://mysite.com"; $url=preg_replace('/\/index\.php\/?$/',"/",$url); $url=preg_replace('/\/index\.php\/?/',"/",$url); $url=preg_replace('/([a-zA-Z])$\/?/',"$1/",$url); echo "$url"; ?>http://mysite.com/intohttp:/mysite.com/. It still might be possible to do this with str_replace, but I'm not sure how yet.
To choose the lesser of two evils is still to choose evil. My personal site
@james, bluwalrus, jshor: Thanks for all reply from you guys,
i have found my self
my be a little poor,
PHP Code:<?
function menu_top(){
$domain = "http://www.mysite.ext"; //can be mysite.com, mysite.us, mysite.co.id, mysite.web.id, and so on
$menu = array(
'Home' => $domain,
'People' => $domain.'/people/',
'News' => $domain.'/news/',
'Blog' => $domain.'/blog/'
);
$current_php_self = str_replace('index.php/', '', $_SERVER['PHP_SELF']);
$current_php_self = str_replace('index.php', '', $current_php_self);
$current_page = $domain.$current_php_self;
//this current page always return something like http://www.mysite.ext/index.php/mypage/
//sometimes return http://www.mysite.ext/index.php
//
//home link, in menu shows http://www.mysite.ext/ , but in current_page return http://www.mysite.ext/index.php
//people link, in menu show http://www.mysite.ext/people/, but in current_page return http://www.mysite.ext/incex.php/people/
//and the other link are too
//
/*
so, i want a regex to remove index.php from $current_page,
like:
http://mysite.com/
http://mysite.com/people/
not like:
http://mysite.com/
http://mysite.com//people/
not like:
http://mysite.com
http://mysite.com/people/
*/
$ret ='<ul>';
foreach($menu as $link_text => $link_url){
if( $current_page == $link_url)
$ret .='<li class="link_active">'.$link_text.'</li>';
else
$ret .='<li><a href="'.$link_url.'">'.$link_text.'</a></li>';
}
$ret .='</ul>';
return $ret;
}
?>
///////////////////////////////////////////////////
///// http://www.mediatutorial.web.id
///////////////////////////////////////////////////
Ah, clever girl. I can't see anything wrong with that and it is so simple too.
To choose the lesser of two evils is still to choose evil. My personal site
Bookmarks