-1
I was wondering if you have how to get a specific text from a txt file using php ?
I can already read this to display it completely as a result in a div, but I needed to take for example a word or a number to display separately in another location. You can do this in PHP or using Javascript ?
Below is my div where displays the results that run the PHP script that reads the text file:
<div id="box_results">
<div id="results" class="results">
<?php
//Abrimos o arquivo em leitura
$arquivo = 'log/speedtest.txt';
$fp = fopen($arquivo, 'r');
//Lemos o arquivo
$texto = fread($fp, filesize($arquivo));
//Transformamos as quebras de linha em etiquetas <br>
$texto = nl2br($texto);
echo $texto;
?>
</div>
</div>
I ask this because this text file is temporary, it is generated every time a form is submitted, ie it updates the information in this text file. And for the results to be displayed after submitting a form, I use the following script:
<script type="text/javascript">
$("#frm").on("submit", function(){
$("#results").html('');
fun();
});
var t;
function recarrega() {
$("#box_results").load(" #results");
$("#execute").hide();
}
function fun() {
t = setInterval(recarrega, 1000);
}
function stop() {
clearTimeout(t);
$("#execute").show();
}
</script>
You can then pick up specific content after this text file is updated ?
Edit:
This is the contents of the text file I will read:
[Parâmetros]
CPU = 512
WAN = 1237
LAN1 = 435
As strange as this file saving solution seems to be, but it would no longer be convenient to use a structured text pattern like JSON, XML, CSV, etc?
– Woss
@Andersoncarloswoss So, in the case I don’t have much knowledge, and I ended up investing in this method that I still had help to do. And in case they are not sensitive information to be saved in the text file then there is no problem in this case they are displayed.
– Rooh Macedo
@But still in this case, I need to find out if you have the ability to do this because I need to read another type of information, which in this case is a speed test, I needed to get information like the CPU of a computer or WAN that will all be recorded in a text file.
– Rooh Macedo