Re: Re: Rewriting string

From: Date: Thu, 13 Jan 2011 20:24:22 +0000
Subject: Re: Re: Rewriting string
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-310742@lists.php.net to get a copy of this message
> $categorys = array('home', 'services', 'gallery', > 'about_us', 'contact_us', > 'testimonials'); If(in_array($_GET['page'], $categories)) { echo '<li><a href=index.php?page='.$_GET['page'].'>'.str_replace("_"," ",$_GET['page']).'</a></li>'; }else{ echo '<li>'.str_replace("_"," ",$_GET['page']).'</li>'; } I normally never write someones code for them but you are just not getting it. The above code works use it. > $deadlink = $_GET['page']; <-- useless > > > On Jan 13, 2011, at 12:45 PM, Nathan Rixham <nrixham@gmail.com> wrote: > David McGlone wrote: >> Hi everyone, >> I think the subject is right, or somewhere close. Anyway I am trying to perform a little >> trickery here with links. In the following code you can see where I am trying to replace the link on >> the current page so it's not a link when on that page. I think I got the general idea of what I >> need to do as you can see in the code I just don't know how to accomplish it, if it's >> possible. >> $categorys = array('home', 'services', 'gallery', >> 'about_us', 'contact_us', 'testimonials'); >> foreach($categorys as $category){ >> $deadlink = $_GET['page']; >> if ($deadlink == 'page') { > > for a short answer, all you need to do is change the above line to: > > if($deadlink == $category) > > and as a slightly colourful variant: > > $categorys = array('home', 'services', 'gallery', > 'about_us', 'contact_us', 'testimonials'); > foreach($categorys as $category){ > $temp = str_replace("_", " ", $category); > $_GET['page'] != $category && $temp = '<a > href="index.php?page='. $category .'">'.$replace.'</a>'; > echo "<li>{$temp}</li>" . PHP_EOL; > } > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php >

« previous php.general (#310742) next »