msn-lijst-naar-mysql
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
/**********************************************
***********************************************
** Author: Thom Wijtenburg **
** Filename: XML2SQL.php **
** Date: 04-08-2007 **
** Version: 3.67 FINAL **
***********************************************
** Function: Convert MSN messenger contact **
** list output to MySQL query. **
** Store mail adresses in database **
***********************************************
**********************************************/
// verbind met database
if (!$db = mysql_connect("$server","$user","$password")){
echo "Mysql Error occured!! Failed to connect to Database server";
}
//echo "Connected to host<br />";
if (!mysql_select_db("test")){
echo "Mysql Error occured!! Failed to select database!";
}
// declareer lees bestand
$xml = file ('contacts/bestandsnaam.ctt');
// DEBUG!! stel user ID in. Dit moet natuurlijk uit je loginscript komen.
$_SESSION['nummer'] = "1";
// Vervang alle XML code door NULL, ' (apostrofe) of );
$xml = str_replace("<?xml version=\"1.0\"?>", "", $xml);
$xml = str_replace("<messenger>", "", $xml);
$xml = str_replace(" <service name=\".NET Messenger Service\">", "", $xml);
$xml = str_replace(" <contactlist>", "", $xml);
$xml = str_replace("</contact>", "'", $xml);
$xml = str_replace(" </contactlist>", ");", $xml);
$xml = str_replace(" </service>", "", $xml);
$xml = str_replace("</messenger>", "", $xml);
// Vervang XML code met standaardvorm query
$xml = str_replace("<contact type=\"1\">", "), (NULL , '" . $_SESSION['nummer'] . "', '", $xml);
// haal alle newlines en whitespaces eruit
$xml = str_replace("\n", "", $xml);
$xml = str_replace("\r", "", $xml);
$xml = str_replace(" ", "", $xml);
// bouw begin query
$sql = "INSERT INTO `test`.`contactlist` (`ID`, `UserID`, `contactMail`) VALUES ";
// inplode de array xml
$sql .= implode("", $xml);
// zorg dat de eerste waarde goed word weergeven
$sql = str_replace("VALUES ),(", "VALUES (", $sql);
// voer query uit
if (!$result = mysql_query($sql)){
// fout! laat de fout zien en echo de query
echo mysql_error();
echo "<br />" . $sql;
}
else{
// gelukt! laat "Succes!" zien.
echo "Succes!";
}
?>
/**********************************************
***********************************************
** Author: Thom Wijtenburg **
** Filename: XML2SQL.php **
** Date: 04-08-2007 **
** Version: 3.67 FINAL **
***********************************************
** Function: Convert MSN messenger contact **
** list output to MySQL query. **
** Store mail adresses in database **
***********************************************
**********************************************/
// verbind met database
if (!$db = mysql_connect("$server","$user","$password")){
echo "Mysql Error occured!! Failed to connect to Database server";
}
//echo "Connected to host<br />";
if (!mysql_select_db("test")){
echo "Mysql Error occured!! Failed to select database!";
}
// declareer lees bestand
$xml = file ('contacts/bestandsnaam.ctt');
// DEBUG!! stel user ID in. Dit moet natuurlijk uit je loginscript komen.
$_SESSION['nummer'] = "1";
// Vervang alle XML code door NULL, ' (apostrofe) of );
$xml = str_replace("<?xml version=\"1.0\"?>", "", $xml);
$xml = str_replace("<messenger>", "", $xml);
$xml = str_replace(" <service name=\".NET Messenger Service\">", "", $xml);
$xml = str_replace(" <contactlist>", "", $xml);
$xml = str_replace("</contact>", "'", $xml);
$xml = str_replace(" </contactlist>", ");", $xml);
$xml = str_replace(" </service>", "", $xml);
$xml = str_replace("</messenger>", "", $xml);
// Vervang XML code met standaardvorm query
$xml = str_replace("<contact type=\"1\">", "), (NULL , '" . $_SESSION['nummer'] . "', '", $xml);
// haal alle newlines en whitespaces eruit
$xml = str_replace("\n", "", $xml);
$xml = str_replace("\r", "", $xml);
$xml = str_replace(" ", "", $xml);
// bouw begin query
$sql = "INSERT INTO `test`.`contactlist` (`ID`, `UserID`, `contactMail`) VALUES ";
// inplode de array xml
$sql .= implode("", $xml);
// zorg dat de eerste waarde goed word weergeven
$sql = str_replace("VALUES ),(", "VALUES (", $sql);
// voer query uit
if (!$result = mysql_query($sql)){
// fout! laat de fout zien en echo de query
echo mysql_error();
echo "<br />" . $sql;
}
else{
// gelukt! laat "Succes!" zien.
echo "Succes!";
}
?>