Pulling Contents from a file
Moderator: General Moderators
Pulling Contents from a file
Ok, heres what I want to do, but have no idea if its possible or if there are any classes/functions available to do it.
Someone enters a word into a page, the code then checks another file for certain pre-defined items, pulling certain words/lines etc from it, then the code displays its findings back on the page.
bah.. its perfectly clear in my head how i want it to work but explaining it is a little tricky..
Someone enters a word into a page, the code then checks another file for certain pre-defined items, pulling certain words/lines etc from it, then the code displays its findings back on the page.
bah.. its perfectly clear in my head how i want it to work but explaining it is a little tricky..
So you want to search a flat file for specific text in it?
Use file_get_contents() to return the file into a string, and using something like strpos() to find the location of the word in your file.
http://www.php.net/file_get_contents
http://www.php.net/strpos
Use file_get_contents() to return the file into a string, and using something like strpos() to find the location of the word in your file.
http://www.php.net/file_get_contents
http://www.php.net/strpos
Not a flat file no...
i want to do a dns lookup on a domain, like the following:
; <<>> DiG 9.2.1 <<>> devnetwork.net
;; global options: printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 12024
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION:
;devnetwork.net. IN A
;; ANSWER SECTION:
devnetwork.net. 14400 IN A 63.247.70.254
;; Query time: 126 msec
;; SERVER: 192.168.2.1#53(192.168.2.1)
;; WHEN: Tue Jun 13 20:18:42 2006
;; MSG SIZE rcvd: 48
I just want to pull the following info from it:
devnetwork.net. 14400 IN A 63.247.70.254
or:
host -ptr devnetwork.net
host: illegal option -- p
Warning: invalid type: r
devnetwork.net has address 63.247.70.254
Now
devnetwork.net doesnt have a PTR record so after doing this check I want it to say "No PTR record found".
i want to do a dns lookup on a domain, like the following:
; <<>> DiG 9.2.1 <<>> devnetwork.net
;; global options: printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 12024
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION:
;devnetwork.net. IN A
;; ANSWER SECTION:
devnetwork.net. 14400 IN A 63.247.70.254
;; Query time: 126 msec
;; SERVER: 192.168.2.1#53(192.168.2.1)
;; WHEN: Tue Jun 13 20:18:42 2006
;; MSG SIZE rcvd: 48
I just want to pull the following info from it:
devnetwork.net. 14400 IN A 63.247.70.254
or:
host -ptr devnetwork.net
host: illegal option -- p
Warning: invalid type: r
devnetwork.net has address 63.247.70.254
Now
devnetwork.net doesnt have a PTR record so after doing this check I want it to say "No PTR record found".
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
Grabbing a DNS, I have no idea (but I am almost certain someone here does). As for all of the other stuff you can have a look at regular expressions and file system functions. File system will be a lot easier to wrap your mind around than regular expressions (unless you have some experience with regex already).
feyd | Please use
As you can see I am using the Find/Replace function to remove what I dont want to be shown.
This seems like the long way around, and i could use the find/repalce fucntion to remove everything I dont want and leave the stuff I do..
I am using this for my new website http://www.domaindiagnosis.com
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
I havent been able to get my head fully around regexpression... here is something thats ive patched together to give you an idea:Code: Select all
<?php
$output = `/usr/bin/host -t ns $query`;
$find [] = "Host $query not found: 3(NXDOMAIN)";
$find [] = "$query name server";
$replace [] = " Domain Not Found - Please make sure you've spelt it correctly";
$replace [] = "";
$output = str_replace($find, $replace, $output);
if (preg_match("^[a-z0-9\:\.\-]+$^", "$output $query"))
{
echo "Name Servers:<pre>$output</pre>";
}
elseif ($domain == ""){
echo "";
}
else {
echo "You have entered an invalid domain name, do not enter 'http://' or 'www.'";
}
?>As you can see I am using the Find/Replace function to remove what I dont want to be shown.
This seems like the long way around, and i could use the find/repalce fucntion to remove everything I dont want and leave the stuff I do..
I am using this for my new website http://www.domaindiagnosis.com
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]