• Advertisement
Sign in to follow this  

[web] Can any one mod this?

This topic is 4173 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

can any one mod this so it says the files header not the files name its self?
<?php 
   foreach( glob("*") as $f )
      echo "<ol><p><a href=\"$f\">$f</a></p>";
?>;


Edit by Fruny: added source block. [Edited by - Fruny on August 13, 2006 12:35:17 AM]

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by lordcorm
can any one mod this so it says the files header not the files name its self?
"<?php foreach(glob("*")as$f)echo"

    $f

    ";?>;"


Um, what?? O.o

Edit: The shock value is over. Your code doesn't look complete. What are you trying to accomplish? The above code needs to be expanded or your example needs to be more fulfilling in order to know what the heck you're doing. :)

Share this post


Link to post
Share on other sites
what i need is a scripts that shows when i put a new file into a folder it shows the files header title not the files title and in order.
Thank you!

Share this post


Link to post
Share on other sites
Next time try and use [ code ] or [ source ] blocks...


Here is some code!



Here is some source!

Share this post


Link to post
Share on other sites
Quote:
what i need is a scripts that shows when i put a new file into a folder it shows the files header title not the files title and in order.
Thank you!


What version of PHP are you using? What do you mean by file header title? The file name? The file type?

Sorting the order of the files can easily be done when you have built an array of the files in question; it's matter of knowing exactly what you need. Sorry, I just don't know what file header title is.

Share this post


Link to post
Share on other sites
This is what i meen:
[code]<head><title>Dark Legion</title></head>[code]
So it says the Dark Legion and not the file name darklegion.html and i dont know what version of php it uses but sure it the latest.

Share this post


Link to post
Share on other sites
Quote:
This is what i meen:
[code]<head><title>Dark Legion</title></head>[code]
So it says the Dark Legion and not the file name darklegion.html and i dont know what version of php it uses but sure it the latest.


You have to close the code bracket like you close HTML tags [/ code] (minus the space).

You want to read only HTML files and grab the contents between <title></title>?

To find out your PHP version:

<?php
phpinfo();
?>

Share this post


Link to post
Share on other sites
yes i want it to only grab the name in between the
<title>...</title>
command and make it show a link to it so i can make a thang on my home page that shows the new updated files.
Also make sure that it shows it in numbers 1,2,3,4,etc.......

Share this post


Link to post
Share on other sites
A really lousy way of doing it would be to open the file as a text-file and search for <title> then read until </title> and put it in a variable. Search for reading files with PHP, it isn't too hard to do.

Share this post


Link to post
Share on other sites
Quote:
Original post by Krisc
A really lousy way of doing it would be to open the file as a text-file and search for <title> then read until </title> and put it in a variable. Search for reading files with PHP, it isn't too hard to do.

HE'S TELLING YOU TO DO THAT WITH PHP.

Sorry for the caps, just a little frustrated. Have you tried to do this on your own. You already have enough info to implement what you want. How about you try it and then come back if you are getting errors or the program is showing the wrong information. 'Kay?

Share this post


Link to post
Share on other sites
can some one just reply with the code that shows the
<title>....</title>
stuff plz!!!!!!!!!! I dont know where to put it into the variable?

Share this post


Link to post
Share on other sites
Here is the code to list all the files in a specified directory.


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

Share this post


Link to post
Share on other sites
this is what I could hammer out very quickly.


<?php
if ($handle = opendir('.')) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
$ext = substr($file, strpos($file, ".")+1);

if ($ext == "html"){
$fh = fopen($file, 'r') or die("Can't open file");
$contents = fread($fh, filesize($file));
$offset = strpos($contents, "<TITLE>");

if ($offset != false) {
$offset2 = strpos($contents, "</TITLE>");
$len = $offset2 - $offset - 7;
$title = substr($contents, $offset+7, $len);
echo $title;
}
$contents = "";
fclose($fh);
}
}
}
closedir($handle);
}
?>

Share this post


Link to post
Share on other sites
I don't understand why you want to do what you're trying to do.


Here is what I do when making php sites, and I'm sure many others do it this way.

I don't know if you're familiar with include statements, but basically you write a file of some code that is shared by all pages in your site. For example, a header and a footer. They would have links to navigate around the page and such.

So you make a header that somewhere in it says:

<title><? echo $title ?></title>



Then in every page that is going to use that header, you put in something like:

<?
$title="Home";
include "header.php";
?>



You can use $title anywhere and that's the title... Again I don't know exactly why you want to do what you want to do, but I feel like this might be something that you should think about doing.

Share this post


Link to post
Share on other sites
Quote:
Original post by lordcorm
can some one just reply with the code?

Do you want to learn how it's done, or do just need someone to do all your work?
Anyway, ntg1976 was already kind enough to do it for you.
When extracting the text between the title tags, you can also consider using regular expressions in PHP. In general, it's a little slower for these simple searches, but it might be useful if whatever you're making should be extended to extract more than just the title.

Share this post


Link to post
Share on other sites
I had enough of this. Lordcom, we're here to help if you're stuck doing things yourself. If you need someone to do all the work for you, go to Help Wanted. Or go learn PHP yourself. It's easy and the manual is great to learn from as well.

Share this post


Link to post
Share on other sites

This topic is 4173 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Guest
This topic is now closed to further replies.
Sign in to follow this  

  • Advertisement