potejam Posted October 26, 2010 Share Posted October 26, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/216840-can-i-create-a-dynamic-command/ Share on other sites More sharing options...
trq Posted October 26, 2010 Share Posted October 26, 2010 Does.... echo '<a href="zenphoto/index.php?album=' . str_replace('-s', '-w', $_GET['album']) . '">link name</a>'; help you? Quote Link to comment https://forums.phpfreaks.com/topic/216840-can-i-create-a-dynamic-command/#findComment-1126458 Share on other sites More sharing options...
jcbones Posted October 26, 2010 Share Posted October 26, 2010 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>'; Quote Link to comment https://forums.phpfreaks.com/topic/216840-can-i-create-a-dynamic-command/#findComment-1126460 Share on other sites More sharing options...
potejam Posted October 26, 2010 Author Share Posted October 26, 2010 Yes, good point... I would need it to work both ways ("w" to "s" and "s" to "w"). That should give me something to work with, and at least a direction to pursue... Thanks for the help! J Quote Link to comment https://forums.phpfreaks.com/topic/216840-can-i-create-a-dynamic-command/#findComment-1126474 Share on other sites More sharing options...
potejam Posted October 26, 2010 Author Share Posted October 26, 2010 By the way, what would this actually be called...? ...so that I can actually search for relevant information in the future... Quote Link to comment https://forums.phpfreaks.com/topic/216840-can-i-create-a-dynamic-command/#findComment-1126475 Share on other sites More sharing options...
potejam Posted November 2, 2010 Author Share Posted November 2, 2010 Just got a chance to try that out. Worked perfectly! Thanks for taking the time; it would have taken me months to figure that out... Quote Link to comment https://forums.phpfreaks.com/topic/216840-can-i-create-a-dynamic-command/#findComment-1129533 Share on other sites More sharing options...
potejam Posted December 16, 2010 Author Share Posted December 16, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/216840-can-i-create-a-dynamic-command/#findComment-1148245 Share on other sites More sharing options...
Anti-Moronic Posted December 16, 2010 Share Posted December 16, 2010 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(). Quote Link to comment https://forums.phpfreaks.com/topic/216840-can-i-create-a-dynamic-command/#findComment-1148281 Share on other sites More sharing options...
laffin Posted December 16, 2010 Share Posted December 16, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/216840-can-i-create-a-dynamic-command/#findComment-1148349 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.