annieone Posted March 8, 2009 Share Posted March 8, 2009 hi, i am using a dynamic folderlist-script in a gallery and it works fine so far. but i do not get it (i am no coder i admit it) how to avoid the first two letters of a dir by using substr method. here is my gallery script which works well except that i would like to prevent folders showing their numbers like 01 at the beginning..: if (isset( $_GET['galerie'] ) ) { echo '<div id="container"><div class="main-content"> <div style="width:auto;white-space:nowrap;height:530px;background:#585850;position:relative;"><div id="preview">'; $bilder = glob( "sets/{$_GET['galerie']}/images/*.jpg" ); natsort( $bilder ); foreach ($bilder as $bild) { $bild = array_pop( explode( "/", $bild ) ); // where to put substr function? echo '<img src="sets/' .$_GET['galerie']. '/images/' .$bild. '" style="margin-right:2px;"/>'; } echo '</div></div></div>'; } thanx a lot for any help in grammar for beginners.. :-\ Quote Link to comment https://forums.phpfreaks.com/topic/148509-help-where-to-put-substr-function-in-gallery-script/ Share on other sites More sharing options...
annieone Posted March 8, 2009 Author Share Posted March 8, 2009 hi, my first post was with wrong code, sorry!! maybe now somebodey can help: i wonder how to avoid the first two letters of a dir by using substr method. here is my gallery script which works well except that i would like to prevent folders showing their numbers like 01 at the beginning..: <?php // Galerien ermitteln $verzeichnisse = glob( "sets/*", GLOB_ONLYDIR ); echo '<div id="nav"><ul>'; foreach ($verzeichnisse as $dir) { $dirname = array_pop( explode( "/", $dir ) ); // where do i put substr function? echo '<li><a href="' .$_SERVER['PHP_SELF']. '?galerie=' .$dirname. '">' .$dirname. '</a></li>'; } echo '</ul><ul><li><a href="main.php">Main</a></li></ul></div><br class="clear" />'; ?> thanx a lot for any help in grammar for beginners.. ??? Quote Link to comment https://forums.phpfreaks.com/topic/148509-help-where-to-put-substr-function-in-gallery-script/#findComment-779868 Share on other sites More sharing options...
RussellReal Posted March 8, 2009 Share Posted March 8, 2009 substr($dir,1) should fetch the whole string except the first 2 characters, note: indexs start at 0 Quote Link to comment https://forums.phpfreaks.com/topic/148509-help-where-to-put-substr-function-in-gallery-script/#findComment-779895 Share on other sites More sharing options...
premiso Posted March 8, 2009 Share Posted March 8, 2009 I do not see where you attempted to do that code. $dirname = substr($dirname, 2); Should remove the first 2 items from the name. EDIT: Beaten to it, but a correction was needed. Should be 2 not 1. Quote Link to comment https://forums.phpfreaks.com/topic/148509-help-where-to-put-substr-function-in-gallery-script/#findComment-779899 Share on other sites More sharing options...
Mchl Posted March 8, 2009 Share Posted March 8, 2009 Could you explain a bit more what you want to do? An example would be nice. [edit] Strange... didn't get warning that there are replies to this topic before I posted... Quote Link to comment https://forums.phpfreaks.com/topic/148509-help-where-to-put-substr-function-in-gallery-script/#findComment-779916 Share on other sites More sharing options...
RussellReal Posted March 8, 2009 Share Posted March 8, 2009 I do not see where you attempted to do that code. $dirname = substr($dirname, 2); Should remove the first 2 items from the name. EDIT: Beaten to it, but a correction was needed. Should be 2 not 1. oh yeah =\.. 0 would be from the start 1 would be after the first, sorry bro premiso is right Quote Link to comment https://forums.phpfreaks.com/topic/148509-help-where-to-put-substr-function-in-gallery-script/#findComment-779917 Share on other sites More sharing options...
annieone Posted March 8, 2009 Author Share Posted March 8, 2009 thanks a lot everyone here, meanwhile i came up with even another idea from a pityful friend and now it looks like this: <?php // Galerien ermitteln $verzeichnisse = glob( "sets/*", GLOB_ONLYDIR ); echo '<div id="nav"><ul>'; foreach ($verzeichnisse as $dir) { $dirname = array_pop( explode( "/", $dir ) ); // $dir=substr($dir, 2); << wrong idea.. ! // better idea..: echo "<li><a href=".$_SERVER['PHP_SELF']."?galerie=".$dirname.">".substr($dirname,2)."</a></li>"; } echo '</ul><ul><li><a href="main.php">Main</a></li></ul></div><br class="clear" />'; ?> again thank you so much, you've been very kind! Quote Link to comment https://forums.phpfreaks.com/topic/148509-help-where-to-put-substr-function-in-gallery-script/#findComment-779965 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.