Forums
This topic is locked
filter file list
Posted 18 Apr 2005 14:39:44
1
has voted
18 Apr 2005 14:39:44 Matt Bailey posted:
I have a function that displays the content of a remote folder in a select list. In the folder are images and thumbnail images. I'm trying to figure out how to filter out the thumbnail images because I don't want them appearing in the select list.My thumbnail filenames all finish like this '_t.jpg', so is there some way I can look for this and then if it's found not display it?
___________________________________
* Sorry... how do you do that again?... *
Replies
Replied 18 Apr 2005 17:30:28
18 Apr 2005 17:30:28 Chris Charlton replied:
Yup, there are two PHP functions to help you. Also there's more advanced methods using preg match, but these should work just fine.
<ul><li><b>str_replace</b> - wwwphp.net/manual/en/function.str-replace.php</li><li><b>substr_replace</b> - www.php.net/manual/en/function.substr-replace.php</li></ul>
~ ~ ~ ~ ~ ~ ~
Chris Charlton <i>- DMXzone Manager</i>
<font size=1>[ Studio MX/MX2004 | PHP/ASP | SQL | XHTML/CSS | XML | Actionscript | Web Accessibility | MX Extensibility ]</font id=size1>
<ul><li><b>str_replace</b> - wwwphp.net/manual/en/function.str-replace.php</li><li><b>substr_replace</b> - www.php.net/manual/en/function.substr-replace.php</li></ul>
~ ~ ~ ~ ~ ~ ~
Chris Charlton <i>- DMXzone Manager</i>
<font size=1>[ Studio MX/MX2004 | PHP/ASP | SQL | XHTML/CSS | XML | Actionscript | Web Accessibility | MX Extensibility ]</font id=size1>
Replied 19 Apr 2005 11:12:02
19 Apr 2005 11:12:02 Matt Bailey replied:
Thanks Chris. I'll have a look at those two functions you mention. After posting I figured out a way of doing it, but your ways might be better. What do you think? This is what I did:
<pre id=code><font face=courier size=2 id=code>$thumbnail = substr($file, -6); //Finds thumbnail suffix and extension
if ($thumbnail != '_t.jpg' and $thumbnail != '_t.gif') {
echo '<option value="',$file,'"'; {
if ($ImageURL == $file) echo ' selected'; echo '>' . $file . '</option>'; //Lists files and selects one based on database entry
}
}</font id=code></pre id=code>
___________________________________
* Sorry... how do you do that again?... *
<pre id=code><font face=courier size=2 id=code>$thumbnail = substr($file, -6); //Finds thumbnail suffix and extension
if ($thumbnail != '_t.jpg' and $thumbnail != '_t.gif') {
echo '<option value="',$file,'"'; {
if ($ImageURL == $file) echo ' selected'; echo '>' . $file . '</option>'; //Lists files and selects one based on database entry
}
}</font id=code></pre id=code>
___________________________________
* Sorry... how do you do that again?... *
Replied 19 Apr 2005 19:05:13
19 Apr 2005 19:05:13 Chris Charlton replied:
<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote><pre id=code><font face=courier size=2 id=code>$thumbnail = substr($file, -6); //Finds thumbnail suffix and extension
if ($thumbnail != '_t.jpg' and $thumbnail != '_t.gif') {
echo '<option value="',$file,'"'; {
if ($ImageURL == $file) echo ' selected';
echo '>' . $file . '</option>'; //Lists files and selects one based on database entry
}
}</font id=code></pre id=code><hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>
Cool, seems fine. Your <i>if</i> statement uses AND, it could also be OR since it's a .jpg or .gif - but most importantly is <b>are you coding XHMTL</b> or regular HTML? I mention because your <pre id=code><font face=courier size=2 id=code>... echo "selected"...</font id=code></pre id=code>
If XHTML, it should be valid...<pre id=code><font face=courier size=2 id=code>selected="selected"</font id=code></pre id=code>
It's being slightly discussed at:
www.dmxzone.com/forum/topic.asp?TOPIC_ID=31447&FORUM_ID=544&CAT_ID=2
Also, since you're doing a lot of replace and inserting variables within HTML, you may want to look at PHP's function called <i><b>sprintf</b></i>. I have a free article on it here:
www.dmxzone.com/showDetail.asp?TypeId=2&NewsId=7073
~ ~ ~ ~ ~ ~ ~
Chris Charlton <i>- DMXzone Manager</i>
<font size=1>[ Studio MX/MX2004 | PHP/ASP | SQL | XHTML/CSS | XML | Actionscript | Web Accessibility | MX Extensibility ]</font id=size1>
if ($thumbnail != '_t.jpg' and $thumbnail != '_t.gif') {
echo '<option value="',$file,'"'; {
if ($ImageURL == $file) echo ' selected';
echo '>' . $file . '</option>'; //Lists files and selects one based on database entry
}
}</font id=code></pre id=code><hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>
Cool, seems fine. Your <i>if</i> statement uses AND, it could also be OR since it's a .jpg or .gif - but most importantly is <b>are you coding XHMTL</b> or regular HTML? I mention because your <pre id=code><font face=courier size=2 id=code>... echo "selected"...</font id=code></pre id=code>
If XHTML, it should be valid...<pre id=code><font face=courier size=2 id=code>selected="selected"</font id=code></pre id=code>
It's being slightly discussed at:
www.dmxzone.com/forum/topic.asp?TOPIC_ID=31447&FORUM_ID=544&CAT_ID=2
Also, since you're doing a lot of replace and inserting variables within HTML, you may want to look at PHP's function called <i><b>sprintf</b></i>. I have a free article on it here:
www.dmxzone.com/showDetail.asp?TypeId=2&NewsId=7073
~ ~ ~ ~ ~ ~ ~
Chris Charlton <i>- DMXzone Manager</i>
<font size=1>[ Studio MX/MX2004 | PHP/ASP | SQL | XHTML/CSS | XML | Actionscript | Web Accessibility | MX Extensibility ]</font id=size1>
Replied 19 Apr 2005 21:36:27
19 Apr 2005 21:36:27 Matt Bailey replied:
This site is just regular HTML at the mo, but I'm hoping to start creating XHTML sites soon, so thanks for the tip. Once again you've been most helpful. Just printing out your sprintf article now, cheers!
___________________________________
* Sorry... how do you do that again?... *
___________________________________
* Sorry... how do you do that again?... *
Replied 20 Apr 2005 20:54:05
20 Apr 2005 20:54:05 Chris Charlton replied:
<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>This site is just regular HTML at the mo, but I'm hoping to start creating XHTML sites soon, so thanks for the tip. Once again you've been most helpful. Just printing out your sprintf article now, cheers!<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>
<img src=../images/dmxzone/forum/icon_smile_cool.gif border=0 align=middle>
<img src=../images/dmxzone/forum/icon_smile_cool.gif border=0 align=middle>