[web] Can any one mod this?

Started by
15 comments, last by Sander 17 years, 8 months ago
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?

Beginner in Game Development?  Read here. And read here.

 

Advertisement
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?
Here is the code to list all the files in a specified directory.

<?phpif ($handle = opendir('.')) {   while (false !== ($file = readdir($handle))) {       if ($file != "." && $file != "..") {           echo "$file\n";       }   }   closedir($handle);}?>
this is what I could hammer out very quickly.

<?phpif ($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);}?>
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.
-Chris
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.
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.

<hr />
Sander Marechal<small>[Lone Wolves][Hearts for GNOME][E-mail][Forum FAQ]</small>

This topic is closed to new replies.

Advertisement