with $phpfiles = glob("*.php"); I get all php files in a folder, with $phpfiles = glob("*?[!index]?.php"); I should get all php files except index.php: however this code, once working, is no more working. In fact the correct code is
$phpfiles = glob("[^index]*.php");
isn’t it?
My aim is to list all php folder’s files (except index.php) and get them linked and to get the meta tag “description” at the right side of every file.
It show the meta tag “description” of a given, single php file.
So, I trying to merge, so to say, these two codes, but unsuccessfully, for my incompetence
What happens, wake689? Warning messages and no meta tag. Here
Warning : get_meta_tags() expects parameter 1 to be a valid path, array given in /mnt/dati/schede/web/web-pro/php-read-metatags.php on line 17
php-read-metatags // file correctly linked Notice : Trying to access array offset on value of type null in /mnt/dati/schede/web/web-pro/php-read-metatags.php on line 21
<?php
echo "<ul>";
$phpfiles = glob("[^index]*.php");
foreach ($phpfiles as $phpfile){
echo '<li><a href="'.$phpfile.'">'.pathinfo($phpfile, PATHINFO_FILENAME).'</a>';
echo "<span>";}
foreach ($phpfiles as $files){
echo "<p><b>$files</b></p>"; //just for testing it
$tags = (get_meta_tags($files));
echo $tags['description']; // line 23
echo PHP_EOL; // line 24
echo "</span></li>";
}
echo "</ul>";
?>
I get this error message (after correctly linking php files)
config.inc
php-read-exif
php-read-metatags
config.inc.php
Notice: Undefined index: description in /mnt/dati/schede/web/web-pro/php-read-metatags.php on line 24
php-read-exif.php
Notice: Undefined index: description in /mnt/dati/schede/web/web-pro/php-read-metatags.php on line 24
php-read-metatags.php
Notice: Undefined index: description in /mnt/dati/schede/web/web-pro/php-read-metatags.php on line 24
Normal debugging techniques, really. First, is it getting the correct filename and opening it successfully? Second, are there any meta tags in the file? The fact that you get an empty array rather than false suggests it is finding the file correctly, but not finding any tags in it.
How about showing one of the files on here, perhaps someone can see why it isn’t finding the tags?
But, if there were other meta tags, they should have been returned in the array with the “description” tag missing. So your empty array suggests that there is still some problem.
I take it you’ve checked the documentation for get_meta_tags() to see if there’s anything relevant there?
I take it you’ve checked the documentation for get_meta_tags() to see if there’s anything relevant there?
To be honest, I “checked” only threads on Stackoverflow and php online manual, but unsuccessfully, so far.
The most relevant is here. But it doesn’t work.
It’s not the problem this thread’s about at this point, but for the record,
does not mean “anything but index.php”.
^ has no meaning to glob.
! negates a set.
But
does not mean this either.
* = any number of characters ? = exactly 1 character [!index] = “Any single character that is not i,n,d,e or x.”
*?[!index]?.php = “Any filename that ends in .php, and the rest of the filename is at least 3 characters long, the second-to-last character being not in the set [i,n,d,e,x].”
Yes, that’s what I meant by the documentation. Well, if it’s still not working, maybe time to show one of the files, obviously with any sensitive stuff blocked out. Post the smallest one.
config.inc.php almost certainly doesnt contain meta-tags; a file like that isnt supposed to be HTML…
Are the meta tags you posted above inside the head tag of the file in question?
Also that first meta tag is missing a name attribute. Not sure if that’ll cause problems…
One difference there is that you are using a URL for the working code, and a file path for the one that does not. On that basis it would be worth checking that you have the correct path, although I would still have expected that you would get false rather than an empty array if that were the problem.
But you’re not pointing to a single file, you’re pointing to a URL. If you point it to a single file without the http at the start, and with the correct path, does it work as expected?
of note, there is no path in glob results; glob isnt recursive. People have over the years suggested/designed recursive glob functions, but the path glob searches is fixed; as such, the found files will be in the current directory. (eventually, RecursiveDirectoryIterator took care of this mostly.)