Forum Moderators: coopster

Message Too Old, No Replies

Read File to get data

         

TheKiller

1:52 am on Jan 25, 2011 (gmt 0)

10+ Year Member



Hello

i know there are some scripts around that read the html files of a site to get the meta tags they use etc

i would like to know how may i read a file to get a part of it

for example

i have this link ...
ExampleDomain.com/Forums/styles/****/template/template.cfg

its content is


#
# phpBB Template Configuration File
#
# @package phpBB3
# @copyright (c) 2006 phpBB Group
# @license http://opensource.org/licenses/gpl-license.php GNU Public License
#
#
# At the left is the name, please do not change this
# At the right the value is entered
# For on/off options the valid values are on, off, 1, 0, true and false
#
# Values get trimmed, if you want to add a space in front or at the end of
# the value, then enclose the value with single or double quotes.
# Single and double quotes do not need to be escaped.
#
#

# General Information about this template
name = ***********
copyright = © 2010, ****************
version = 3.0.8

# Defining a different template bitfield
template_bitfield = lNg=




How may i make a PHP File to read that page and get "version" as a string ?

and the string called $Version to echo 3.0.8

Apologizes for my silly way of explaining :)

rocknbil

5:51 pm on Jan 25, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Figure out how to read in the file (there are many ways) and read it line by line:


$version = null;
foreach ($lines as $line) {
if (preg_match('/^version/i',$line)) {
list ($tag,$Version) = explode ('=',$line);
// if you want to remove space, or use str_replace()
$Version = preg_replace('/\s+/','',$Version);
break; // no need to read in the rest of the file
}
}

TheKiller

5:25 pm on Jan 26, 2011 (gmt 0)

10+ Year Member



hmm... in what string do i add the link to query the file ?

should we use file_get_contents ?

TheKiller

12:57 am on Jan 28, 2011 (gmt 0)

10+ Year Member



Well?

Matthew1980

9:35 am on Jan 28, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there TheKiller,

As Rocknbil hints at: file("template.cfg"); this will return the contents of the file in array format, then as your in an array use the foreach to loop through each key=>value:-

Add the 'skip empty lines flag' to this so that your not wasting processing time reading null data.

$line = file("template.cfg", FILE_SKIP_EMPTY_LINES);

foreach($line as $lines){
//do as rocknbil suggests
}

That would be fine, and as your wanting to iterate through each returned line, file() will do the job better in this instance as file_get_contents() reads the entire file into a string, which could make the execution of this a little slow, at least that's how I see it to be :)

Hope that makes sense.

Cheers,
MRb

rocknbil

5:18 pm on Jan 28, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well?


fopen [php.net].
file [php.net].
file_get_contents [us2.php.net].

There are about a half a dozen ways to approach the problem, M's works fine too . . .

TheKiller

8:07 am on Feb 2, 2011 (gmt 0)

10+ Year Member



That Works Perfect !

Thank you very much RocknBill and Matt ! :DD


now i got to find a way how to detect the rest of the link from the default forums domain :|

like if i enter the domain for a forum i need to get the style folder name ..

Dos anyone know how may i Find the {STYLE_NAME}?

[somesite.com...]

Could i use the link to some image and get the style name?
like look for icon_logout around the site and get the stylename? :|


/styles/LOTD/theme/images/icon_logout.png

Sorry for my bad english.. jusst woke up

Wittner

9:10 am on Feb 2, 2011 (gmt 0)

10+ Year Member



Not sure I'm fully understanding what you want. Are you looking for a file from another domain? Have you tried using PHP's cUrl library? This will allow you to get information (including Meta information) from a remote file using HTTP

cheers,

Wittner

rocknbil

6:21 pm on Feb 2, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Are you executing this from within phpBB? If so, look around for the configuration, like WordPress, it's probably carried around as a global variable.

TheKiller

1:08 pm on Feb 3, 2011 (gmt 0)

10+ Year Member



All i want to do is create a form where you put the url to the phpbb board .

When you submit the form it looks up for the template.cfg file . reads the version and echo s it to you

but as the .cfg file is in the template folder of the style for example prosilver
idk how to look up for the file ..

TheKiller

9:40 pm on Feb 6, 2011 (gmt 0)

10+ Year Member



Up