Forum Moderators: coopster
I have a bunch of files in a directory and each file (at some point) will have a line like this:
$title="My page title";
I need to extract the value of $title from each file in the directory to make a dynamic menu.
Problem is that I break out in a cold sweat just thinking about regexp, is their a simple way to do this?
Cheers
Nick
loop through your directory and for each file you can grab the title with this (can't test the ereg right now so let's it's quite possible it's not functional yet):
if (ereg("\$title=\"([^\"]+)\";", $filecontent, $regs) {
$title = $regs[1];
} else {
$title = "";
}
<added>On a second thought, you could always make sure that the actual line is the first line of every file and you can simply read the file grab the first line, grab the $title content with a simple substring trick</added>
mavherick
<?
$dir = opendir("/path/to/files/");
while (($file != readdir($dir))!==false) {
if ($file!="." && $file != "..") {
if (is_file("/path/to/files/".$file) {
include ("/path/to/files/".$file);
$allTitles[] = $title;
}
}
}
If you need to extract the title from the title tag, well I guess the previous loop will work but you'll need to change the include line for, probably, a regex expression.
Hope this helps, good luck!
Hope this helps...
[web.lconn.com...]
Thor