View difference between Paste ID: f37912925 and
SHOW: | | - or go back to the newest paste.
1-
1+
<?php 
2
3
include error_reporting(0);
4
5
// Connect to database of your joomla site
6
7
$host = 'localhost';
8
$dbusername = 'xxx';
9
$dbpassword = 'xxxx';
10
$dbname = 'xxxx';
11
$filename = 'yourfilename.txt';
12
13
$conn1 = mysql_connect("$host", "$dbusername", "$dbpassword") or die("Connection Failed");
14
mysql_select_db("$dbname" ,$conn1)or die("Connection to LIVE database failed!");
15
16
// Set mysql character set
17
mysql_query("SET NAMES 'utf8'");
18
19
20
// Little clean up function
21
function cleanup($srting)
22
{
23
	$srting = trim($srting);
24
	$srting = rtrim($srting);
25
	$srting = str_replace('<br>','', $srting);
26
	$srting = str_replace('\n','', $srting);
27
	$srting = str_replace('\r','', $srting);
28
	$srting = str_replace('-','', $srting);
29
	$srting = preg_replace('/\s\s+/',' ', $srting);
30
	return $srting;
31
}
32
33
34
function str2upper($text){
35
   return strtr($text,
36
   "abcdefghijklmnopqrstuvwxyz".
37
   "\xB1\xE6\xEA\xB3\xF1\xF3\xB6\xBC\xBF". // ISO 8859-2
38
   "\xB9\x9C\x9F", // win 1250
39
   "ABCDEFGHIJKLMNOPQRSTUVWXYZ".
40
   "\xA1\xC6\xCA\xA3\xD1\xD3\xA6\xAC\xAF". // ISO 8859-2
41
   "\xA5\x8C\x8F"  // win 1250
42
   );
43
} 
44
45
$file = file_get_contents("./$filename");
46
47
echo "File is loaded! <br />";
48
49
flush();
50
51
52
53
$a=0;
54
$b=12600;  // Number of tearms (lines) in your file
55
56
while ($a < $b){
57
	
58
$rows = explode("\t", $file); 
59
$rows = explode("\t", $rows[$a]);
60
$rows = $rows[0];
61
62
$ime = explode("(", $rows);
63
$ime = $ime[0];
64
$naziv = explode("-", $ime);
65
$naziv = $naziv[0];
66
$naziv = cleanup($naziv);
67
$naziv = mysql_real_escape_string($naziv);
68
69
70
$slovo = mb_substr($naziv,0,1,'UTF-8');
71
$slovo = str2upper($slovo);
72
if ($slovo == ' ' or $slovo == '')
73
{
74
	$slovo = mb_substr($naziv,1,2,'UTF-8');
75
    $slovo = str2upper($slovo);
76
}
77
78
$slovo = str_replace('&#269;','&#268;', $slovo);
79
$slovo = str_replace('&#263;','&#262;', $slovo);
80
$slovo = str_replace('�','�', $slovo);
81
$slovo = str_replace('�','�', $slovo);
82
$slovo = str_replace('&#273;','&#272;', $slovo);
83
84
85
$slovo = mysql_real_escape_string($slovo);
86
87
$opis = explode(''.$naziv.'', $rows);
88
$opis = explode("\t", $opis[1]);
89
$opis = $opis[0];
90
$opis = cleanup($opis);
91
$opis = mysql_real_escape_string($opis);
92
93
$opis_no = strlen($opis);
94
95
$date = date('Y-m-d H:i:s');
96
97
// Check if term is alredy in databese
98
99
$result = mysql_query("SELECT * FROM jos_glossary WHERE tterm = '$naziv' LIMIT 1",$conn1) or die(mysql_error($conn1)); 
100
$row = mysql_fetch_row($result);
101
if ($row != '') {$check = 'NO';}
102
elseif ($row == '') {$check = 'UPDATE';}
103
104
105
// if not update db
106
if ($check == 'UPDATE' and $opis_no > 3)
107
{	
108
109
echo '<br />- Slovo: '.$slovo.' -  Ime: '.$naziv.' Opis : '.$opis.'<br />';
110
111
112
flush();
113
114
$sql = "INSERT INTO `YOUR_DATABASE_PNAME`.`jos_glossary`
115
							(
116
							 		 `tletter`, 
117
									 `tterm`, 
118
									 `tdefinition`, 
119
									 `tdate`, 
120
									 `teditdate`, 
121
									 `published`, 
122
									 `catid`, 
123
									 `checked_out` 
124
									
125
						 ) VALUES ( 
126
									'$slovo',
127
									'$naziv',
128
									'$opis',
129
									'$date',
130
									'$date',
131
									'1',
132
									'1',
133
									'0');";
134
135
136
137
mysql_query($sql, $conn1) or die(mysql_error($conn1));
138
139
}
140
else {
141
	$a++;
142
	} // IF End
143
	
144
	
145
$a++;
146
}// While end
147
148
149
?>