UPDATED:
I am using RecursiveIteratorIterator to scan the directories to read index.html file.
Now, based on the Pubname and Pubversion, i am trying to read the corresponding index.html file, to get the values of Readability Grade, Readability Score etc. (by storing the values in local storage)
The values are fetched from local storage if i use the html and JS code separately, but after i integrate into php, it is not working.
Code:
<?php
//error_reporting(0);
//Get Pub version
function get_version($path){
$needle = "=";
if(($pos = strpos($path, $needle)) != 0){
$bits = str_split($path, $pos + strlen($needle));
$integer_count = 0;
for($x = 0; $x < strlen($bits[1]); $x++){
if(is_numeric($bits[1][$x])){
$integer_count++;
}else{
break;
}
}
if($integer_count > 0){
$bits = str_split($bits[1], $integer_count);
return $bits[0];
}
}
return -1;
}
$it = new RecursiveDirectoryIterator("C:\Users\Sachin_S2\Desktop\Script");
foreach(new RecursiveIteratorIterator($it,RecursiveIteratorIterator::SELF_FIRST) as $file) {
//IGNORE FILE TYPES
//$filetypes = array("jpg", "png", "pdf", "css", "csv","log","txt");
$htmlfiles = array("html");
$filetype = pathinfo($file, PATHINFO_EXTENSION);
if (in_array(strtolower($filetype), $htmlfiles)) {
// skip dot files while iterating
$it->setFlags(RecursiveDirectoryIterator::SKIP_DOTS);
$files = array($file);
$pathname = $file->getPathname();
print_r($pathname);
$version = get_version($pathname);
if($version > 0){
// use $version to read correct file
include 'html/home.html';
}
echo '*********************************************************************************'.'<br/><br/>';
}
}
html/home.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<title>SEO Metrics</title>
</head>
<body>
<!--Begin script code-->
<form name="myform3">
<!--
<input type="hidden" name="formvar" value="">
<input type="file" name="file" id="file">
<p id="demo"></p><br/><br/>
-->
<div class="form-group">
<label>Readability Grade:</label>
<input type="text" class="form-control" id="grade">
</div>
<div class="form-group">
<label>Readability Score:</label>
<input type="text" class="form-control" id="score">
</div>
<div class="form-group">
<label>Total Word Count:</label>
<input type="text" class="form-control" id="words">
</div>
</form>
<!--END script code-->
<!--Custom JS code-->
<script src="js/home.js"></script>
</body>
</html>
js/home.js
$(document).ready(function() {
document.getElementById('file').onchange = function() {
const file = this.files[0];
const reader = new FileReader();
reader.onload = (event) => {
const file = event.target.result;
const allLines = file.split(/\r\n|\n/);
let arr = allLines;
arr.forEach((kv) => {
if (kv.includes("Flesh-Kincaid Grade Level")) {
var fetch_grade = kv.replace(/<\/?[^>]+(>|$)/g, "");
var formated_grade = fetch_grade.split(":").pop(); //Remove part of the string before ":"
localStorage.setItem("Readability_Grade", formated_grade);
document.getElementById('grade').value = localStorage.getItem("Readability_Grade").replace(/\s/g, ""); //Assign localStorage to text box
localStorage["Readability_Grade"] = grade.value;
//alert(formatedgrade);
}
if (kv.includes("Flesh Reading Ease Score")) {
var fetch_score = kv.replace(/<\/?[^>]+(>|$)/g, "");
var formated_score = fetch_score.split(":").pop();
localStorage.setItem('Readability_Score', formated_score);
document.getElementById('score').value = localStorage.getItem("Readability_Score").replace(/\s/g, "");
//alert(formatedscore);
}
if (kv.includes("Reuse Metrics Score")) {
var metricscore = kv;
//alert(metricscore);
}
if (kv.includes("Total words")) {
var totalwords = kv.replace(/<\/?[^>]+(>|$)/g, "");
var total_words_formated = totalwords.split(":").pop();
localStorage.setItem('Word_Count', total_words_formated);
document.getElementById('words').value = localStorage.getItem("Word_Count").replace(/\s/g, "");
//alert(totalwords);
}
});
};
reader.onerror = (event) => {
alert(event.target.error.name);
};
reader.readAsText(file);
};
});
Output:
On reading this php script, i should be able to read index html (for each file paths - based on pubname and version), and get the values of Readability_Grade and score etc., which i am not able to get.

ESXi_6.7_GSG_Pub=9?