Hello everyone, I’m here with a question… I’ve searched high and low for a way to do this and oddly enough, there have been no results in finding any examples of the script I’m trying to accomplish.
Let me set this up for you all first… I have a web site that uses a template… The pages are php… And for example on my navigation bar I have links to other pages…
Example:
Dogs
Cats
Birds
Snakes
Now what I am attempting to accomplish is to have it show how many links are on each of those pages next to the link in the template… example…
Dogs (5)
Cats (3)
Birds (2)
Snakes (3)
Now I’ve came up with this…
<?php
function countLinks($myfile)
{
$fh = fopen($myfile,'r');
$theData = fgets($fh);
fclose($fh);
$matches = array();
if( preg_match_all("/href/i", $theData, $matches))
{
echo "(" . $matches[0] . ")";
}
else
echo "(0)";
}
?>
Dogs<?php countLinks("dogs.php") ?>
Cats<?php countLinks("cats.php") ?>
Birds<?php countLinks("birds.php") ?>
Snakes<?php countLinks("snakes.php") ?>
I just keep getting (0) as the outcome… Any help with this would greatly be appreciated.
Thank you.