You need to read the file, find some data and output data using PHP

I am new to PHP (never used it until tonight) and I need to use a PHP script to read the contents of the file on my website (http://kylemills.net/Geocaching/BadgeGen/MacroFiles/BadgeGenBeta.gsk), and then take some specific variable data and output it.

For example: if my file contains the text:


random text
Here is some text
#There is some text here too
$Version = "V2.2.23 Beta"
random text
#some more text
$Text="some text"

If the contents of my file were above, I need a script to return "V2.2.23 Beta" (without quotes). The idea is that when you update the file, the version changes, and I want it to be reflected on my site.

I apologize if I don't make any sense ... any help would be appreciated :)

-Thank you, Kyle

+3
3
preg_match('!Version.*?"([^"]+)"!m', file_get_contents('/path/to/file'), $matches);
var_dump($matches);
+3
+1

simply. just update (inside the file) "$ Version = 'V2.2.23 Beta'" to "<? php $ Version = 'V2.2.23 Beta' ;?>"

then wherever you want to use it:

<?php 
echo '<!--';
include 'myfile.txt';
echo '-->';
echo $Version;
?>
0
source

Source: https://habr.com/ru/post/1748080/


All Articles