Jump to content

[SOLVED] applying text styles to php


TONYTOC

Recommended Posts

I have a page that pulls up all the files in a folder for download. My problem is 2 fold. First i dont know how to apply a text style i have to the results (they are purple and i want them white) and second i have no idea how make them into columns.

 

here is my syle:

<style type="text/css">

<!--

.downloadtext {

font-family: Arial, Helvetica, sans-serif;

font-size: medium;

font-style: normal;

color: #FFF;

text-decoration: none;

text-align: left;

 

}

And here is what i have to pull up the files:

<?php

 

$count = 0;

if ($handle = opendir('demos')) {

while (false !== ($file = readdir($handle))) {

if ($file != "." && $file != "..") {$count++;

print("<a href=\"/demos/".$file."\">".$file."</a><br />\n");

}

}

 

closedir($handle);

}

?>

I have tried..... print("<a href=\"/demos/".$file."\"><span class="downloadtext">".$file."</a><br />\n");but of course it does not work.

 

My vision was to have the files in 4 rows of 20 on a single page (i have not went far enough to change font size(what i have will be to big eventually).

 

Very very new to this so if my question sounds like gibberish just let me know. Here is what i get with the above code:

phptrouble.jpg

 

Link to comment
Share on other sites

Hmm maybe im not applying this correctly. First i only have the style setup in this particular .php and do not have it in my style.css.  Do i need to put this syle into my .css page or is there a way to just reference from inside this .php.

Link to comment
Share on other sites

ok i finally got it.

print("<a href=\"/demos/".$file."\"><span class='downloadtext'>".$file."</a><br />\n");
Thx for the ' vs " tip.

 

Now i just need to know how to list them into 4 columns. All the help on columns is geared for table querys which i cant seem to apply to my situation.

Link to comment
Share on other sites

using your old code

 

 

<?php

$count = 1;
if ($handle = opendir('demos')) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
	print("<a href=\"/demos/".$file."\"><span class='downloadtext'>".$file."</a>  -  \n");

	$count++;

	if ($count==4){
		print("<br />");
		$count=1;
		}//end if

	}//end if
}

closedir($handle);
}
?>


 

ugly, but it'll work :D

Link to comment
Share on other sites

No need to use the span...

<?php

$count = 1;
if ($handle = opendir('demos')) {
while (false !== ($file = readdir($handle))) {
   if ($file != "." && $file != "..") {
      print('<a href="/demos/' . $file . '" class="downloadtext">' . $file . "</a>  -   \n");
      
      $count++;
      
      if ($count==4){
         print("\n<br />\n\n");
         $count=1;
         }//end if
         
      }//end if
   }

closedir($handle);
}
?>


Link to comment
Share on other sites

Are you trying to make me look like an underachiever Andy-H ? :D

 

lol I wouldn't do that  ::)

 

You tried to access the address http://192.168.1.178/ which is currently unavailable. Please make sure that the Web address (URL) is correctly spelled and punctuated, then try reloading the page.

Link to comment
Share on other sites

<?php

$count = 0;
if ($handle = opendir('demos')) {
while (false !== ($file = readdir($handle))) {
   if ($file != "." && $file != "..") {
      echo '<a href="/demos/' . $file . '" class="downloadtext">' . substr($file, 0, strpos($file, '.')) . "</a>  -    ";
      
      $count++;
      
      if ($count % 4 === 0){
         echo " <br />  ";

         }//end if
         
      }//end if
   }

closedir($handle);
}
?>

 

That work?

Link to comment
Share on other sites

I really need to leave the file names intact as its the best way to find the match you are looking for since they are date and time stamped. As far as size being an issue, i can change the text size to anything. Are you saying that if i reduce the size then the script you gave me should list them properly? Ill play around with that and see what happens. Your guys input is greatly appreciated.

 

edit: crap you guys are too fast. :)

Link to comment
Share on other sites

That script will just get rid of the extention, Might need to add -1 to the strpos, cant remember. Also, looking at the source it adds a <br /> After every link, using the modulus operator may or may not make the difference but its worth a shot?

Link to comment
Share on other sites

<?php

$count = 0;
if ($handle = opendir('demos')) {
while (false !== ($file = readdir($handle))) {
   if ($file != "." && $file != "..") {
      echo '<a href="/demos/' . $file . '" class="downloadtext">' . substr($file, 10, strpos($file, '.')) . "</a>  -    ";
      
      $count++;
      
      if ($count % 4 === 0){
         echo " <br />  ";

         }//end if
         
      }//end if
   }

closedir($handle);
}
?>

Try that, it will remove the [-TOC-]CTF- part

Link to comment
Share on other sites

here goes :D

 


<?php

$count = 0;
if ($handle = opendir('demos')) {
while (false !== ($file = readdir($handle))) {
   if ($file != "." && $file != "..") {
     
    $string=substr($file,11,-14);
$string=str_replace('_','/',$string);

      echo '<a href="/demos/' . $file . '" class="downloadtext">' . $string . "</a>  -    ";
      
      $count++;
      
      if ($count % 4 === 0){
         echo " <br />  ";

         }//end if
         
      }//end if
   }

closedir($handle);
}
?>

 

and this will make the useless hour min sec go away, as well as those unsightly underscores, just play around with the negative number if u wanna keep the hour/min/sec

Link to comment
Share on other sites

ANNNNDDDD

 

 

u can add this: to make the date customizeable:

 

$string=substr($file,11,-14);
$string=str_replace('_','/',$string);
$string=strtotime($string);

$string=date('F D Y',$string); // or watever format for date u want  (use php.net


 

http://us3.php.net/manual/en/function.date.php

 

watever u put in the ' ' of the date will show based off the values at php.net

Link to comment
Share on other sites

Thanks guys! I believe im all setup now thanks to you all. I would have never gotten there on my own. Those time stamps are when the actual match was recorded on the server so i had to leave them in there. I changed it to 3 columns to keep the files fairly legible. Thanks again. :)

Link to comment
Share on other sites

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.