Jump to content

Recommended Posts

I am a newbie to PHP and don't know the lingo.  As you can imagine it's quite hard to find advice through a search engine when you don't know the terms you should be searching for!  So I'm hoping I can get some advice or leads here...

 

I have a website using a zenphoto photo gallery.  I've adapted the CSS/PHP though trial and error to suit my own needs, but now I am thinking of changing the set up of the web page.

 

I've got 10 galleries in 5 "categories", like this:

category1-s

category1-w

category2-s

category2-w

category3-s

category3-w

and so on...  each category has 2 related options...

 

What I already have is an index for all these categories, where a user can click on the link that says "Category1-S" and it leads to something like this ...zenphoto/index.php?album=category1-s

 

That works fine, but what i WANT to have is a dynamic link on THAT page that will link to the related page.  So on zenphoto/index.php?album=category1-s there would be a link that references the gallery "category1-s" truncates the "s" and adds "w" in its place, so the actual link would be "zenphoto/index.php?album=category1-w"

 

On the page for category2-s that link would read "zenphoto/index.php?album=category2-w" and on the page category3-s the link would read "zenphoto/index.php?album=category3-w"

 

The link would be dynamic and would reference the actual URL of the page in order to create the link.  I feel that this must be possible, but I don't know what it would be called, so my searches haven't found anything...

 

Any help anyone can give would be very appreciated!

thanks,

J

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/216840-can-i-create-a-dynamic-command/
Share on other sites

Thorpe's will work, but if you need the w's turned to s's also, then you may think of something like this.

 

$link = $_GET['album'];

$link = (substr($link,-1) == 's') ? substr($link,0,-1) . 'w' : substr($link,0,-1) . 's'; //if last letter is 's', then change it to 'w' else change it to 's'.

echo '<a href="' . $link . '">New Album</a>';

 

  • 1 month later...

Problem: This had been working fine for a few days and was giving me exactly what I needed.  I was using:

 

$link = $_GET['album'];

 

$link = (substr($link,-1) == 's') ? substr($link,0,-1) . 'w' : substr($link,0,-1) . 's'; //if last letter is 's', then change it to 'w' else change it to 's'.

 

echo '<a href="' . $link . '">New Album</a>';

 

When I was on the page album/category1-s/ it changed the link on that page to album/category1-w/ (and vice versa), just how I wanted.  But then I started getting something different out of the blue.  On page album/category1-s// the link on that page instead read album/category1-s/category1-ss/ and on the page album/category1-w/ the link instead read album/category1-w/category1-ws/.  I restarted my computer and the problem was solved, oddly enough.  But then the next time I tried to work with the page, the issue returned and has stayed ever since.

 

Any idea what the problem is and how to fix it?

Maybe try:

 


$link = (substr($link,-1) == 's') ? str_replace('-s', '-w', $link) : str_replace('-w', '-s', $link);

 

By the way, it's called 'string manipulation'. There are lots of functions for this:

 

http://php.net/manual/en/book.strings.php

 

Take note of str_replace(), substr() and strpos().

 On page album/category1-s// the link on that page instead read album/category1-s/category1-ss/ and on the page album/category1-w/ the link instead read album/category1-w/category1-ws/.  

 

the substr solutions don't account for anything other than ending in w or s, the str_replace method would work, but only if yer certain that the match string is unique.

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.