Martin Kaspar
unread,Dec 12, 2010, 10:04:37 AM12/12/10Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to PHP Hacks
hello everybody!
This is just basic script, where i try to modify for the needs. I try
to play with it. i want to parse some data. The whole script has
the three parts are:
1. Fetching
2. parsing
3. storing
i want to put all into one script: Two are allready put together -
there all seems to be clear...
So this thread is one that asks for the combining two parts of a
script - how to invoke a variable between them
What has happened untill now:
1st i need to have a connection to database lets say MySQL. I will
suggest to use mysqli instead of mysql.
Well - okay i safe this db.php
$host="localhost"; //database hostname
$username="******"; //database username
$password="******"; //database password
$database="******"; //database name
?>
Now i am going to take a new script and save this config.php
<?php
require_once('db.php'); //call db.php
$connect=mysqli_connect($host,$username,$password); //connect to mysql
through mysqli
if(!$connect){
die("Cannot connect to host, please try later."); //throw error if any
problem
}
else
{
$select_db=mysqli_select_db($database); //select database
if(!$select_db){
die("Site Database is down at the moment, Please check later. We will
be back shortly."); // error if cannot connect to database or db does
not
exist
}
}
?>
Now i have to take care for the script, that takes the files (note
this is very basic - it is only a proof of concept.
In the real situation i will take cURL since cURL is much much nicer
and more elegant and faster etc.
<?php
require_once('config.php'); // call config.php for db connection
$content = file_get_contents("[COLOR="darkred"][B]<-here the path to
the file goes in-> Position XY! an URL is here [/B][/COLOR]");
var_dump($content);
$pattern = '/<td>(.*?)<\/td>/si';
preg_match_all($pattern,$content,$matches);
foreach ($matches[1] as $match) {
$match = strip_tags($match);
$match = trim($match);
var_dump($match);
$sql = mysqli_query("insert into tablename(contents) values
('$match')");
}
?>
Note: This is just basic script, where you can modify it for your
taste and can play with it.
Question: If i have stored the URLs that i want to parse in a local
file - how do i "call" them in the script.
How do i do the call to file where the URLs (there are more than 2500
URLs that have to be parsed) at the
following position: $content = file_get_contents("[COLOR="darkred"]
[B]<-here the path to the file goes in-> Position XY! an URL is here
[/B][/COLOR]");
The folder with the URLs is stored in the same folder as the scripts
reside!
Many thanks for all hints and for a starting point!
if i have to write more - or if you need more infos - or if i have to
be more concrete, just let me know!
i love to hear from you!
matze