vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Hey (https://vborg.vbsupport.ru/showthread.php?t=63342)

Owen 04-02-2004 01:29 PM

Hey
 
I am currently making a gallery and have come a long way.

What I want to do now is:
$title=$name

where $name is file-with-dashes.jpg

Now I want $title to be $name with dashes replaced with spaces and .jpg removed.

I have shortened text before but never chopped off the ending...

NTLDR 04-02-2004 01:38 PM

PHP Code:

$title substr(str_replace('-'' '$name), 0, -4); 

Should do it.

Owen 04-02-2004 01:39 PM

thanks man! I'll post a link to the gallery here once it's done.

Boofo 04-02-2004 01:44 PM

Quote:

Originally Posted by NTLDR
PHP Code:

$title substr(str_replace('-'' '$name), 0, -4); 

Should do it.

I'm curious, what is the 0 and the -4 in this code for?

NTLDR 04-02-2004 01:45 PM

The 0 is the start position and the -4 is the end position, ie chop 4 characters off the end.

http://uk.php.net/substr

Boofo 04-02-2004 01:47 PM

Oh, ok, you mean like chop off the .jpg or .gif?

NTLDR 04-02-2004 01:50 PM

Yep :)

Boofo 04-02-2004 01:57 PM

Thanks! See? Even an old dog can learn new tricks. ;)

Owen 04-02-2004 02:09 PM

What if I want to display the first word that comes before a dash?

like:
file-with-dashes.jpg = file

NTLDR 04-02-2004 02:10 PM

PHP Code:

$parts explode('-'$name);
$file $parts[0]; 


Owen 04-02-2004 03:01 PM

Code:

<?php
if ($handle = opendir('.')) {
  while (false !== ($file = readdir($handle))) {
      if ($file != "." && $file != "..") {
          echo "$file\n";
      }
  }
  closedir($handle);
}
?>

How do I exclude index.php from this? and if possible anything other than folders.

Dean C 04-02-2004 04:26 PM

www.php.net/is_dir function checks for directories :)

Owen 04-02-2004 04:50 PM

Yup I figured it out. I used the readdir function.

Owen 04-02-2004 05:00 PM

How do I get rid of those dots? Also how do I sort this alphabetically?

PHP Code:

<?php
   $path 
"."// even "."
   
if ($dir = @opendir($path)) {
       while ((
$file readdir($dir)) !== false) {
           if (
is_dir($path."/".$file)) {
               echo 
$file."<br />";
           }
       }  
       
closedir($dir);
   }
?>

Displays:
.
..
Ford
Infiniti
Mercedes
BMW
Nissan
Volvo

Owen 04-02-2004 09:02 PM

Well I did an extremely crude fix:

PHP Code:

<?php
   $path 
"."// even "."
   
if ($dir = @opendir($path)) {
       while ((
$file readdir($dir)) !== false) {
           if (
is_dir($path."/".$file)) {
        
$title str_replace('.''<img width=0 height=0 border=0>'$file);
               echo 
"<a href=\"$file/\">$title<a/><br>";
           }
       }  
       
closedir($dir);
   }
?>


Velocd 04-02-2004 09:34 PM

The 2nd argument of str_replace can be blank. You can substitute the first argument with an empty string, instead of using an image tag (which makes no sense).

Owen 04-02-2004 10:15 PM

No if I put a space in the br's have effect, but if there is 0 pix images there is nothing to <br>


All times are GMT. The time now is 08:34 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01072 seconds
  • Memory Usage 1,755KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_code_printable
  • (5)bbcode_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (17)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete