Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include error_reporting(0);
- // Connect to database of your joomla site
- $host = 'localhost';
- $dbusername = 'xxx';
- $dbpassword = 'xxxx';
- $dbname = 'xxxx';
- $filename = 'yourfilename.txt';
- $conn1 = mysql_connect("$host", "$dbusername", "$dbpassword") or die("Connection Failed");
- mysql_select_db("$dbname" ,$conn1)or die("Connection to LIVE database failed!");
- // Set mysql character set
- mysql_query("SET NAMES 'utf8'");
- // Little clean up function
- function cleanup($srting)
- {
- $srting = trim($srting);
- $srting = rtrim($srting);
- $srting = str_replace('<br>','', $srting);
- $srting = str_replace('\n','', $srting);
- $srting = str_replace('\r','', $srting);
- $srting = str_replace('-','', $srting);
- $srting = preg_replace('/\s\s+/',' ', $srting);
- return $srting;
- }
- function str2upper($text){
- return strtr($text,
- "abcdefghijklmnopqrstuvwxyz".
- "\xB1\xE6\xEA\xB3\xF1\xF3\xB6\xBC\xBF". // ISO 8859-2
- "\xB9\x9C\x9F", // win 1250
- "ABCDEFGHIJKLMNOPQRSTUVWXYZ".
- "\xA1\xC6\xCA\xA3\xD1\xD3\xA6\xAC\xAF". // ISO 8859-2
- "\xA5\x8C\x8F" // win 1250
- );
- }
- $file = file_get_contents("./$filename");
- echo "File is loaded! <br />";
- flush();
- $a=0;
- $b=12600; // Number of tearms (lines) in your file
- while ($a < $b){
- $rows = explode("\t", $file);
- $rows = explode("\t", $rows[$a]);
- $rows = $rows[0];
- $ime = explode("(", $rows);
- $ime = $ime[0];
- $naziv = explode("-", $ime);
- $naziv = $naziv[0];
- $naziv = cleanup($naziv);
- $naziv = mysql_real_escape_string($naziv);
- $slovo = mb_substr($naziv,0,1,'UTF-8');
- $slovo = str2upper($slovo);
- if ($slovo == ' ' or $slovo == '')
- {
- $slovo = mb_substr($naziv,1,2,'UTF-8');
- $slovo = str2upper($slovo);
- }
- $slovo = str_replace('č','Č', $slovo);
- $slovo = str_replace('ć','Ć', $slovo);
- $slovo = str_replace('ž','Ž', $slovo);
- $slovo = str_replace('š','Š', $slovo);
- $slovo = str_replace('đ','Đ', $slovo);
- $slovo = mysql_real_escape_string($slovo);
- $opis = explode(''.$naziv.'', $rows);
- $opis = explode("\t", $opis[1]);
- $opis = $opis[0];
- $opis = cleanup($opis);
- $opis = mysql_real_escape_string($opis);
- $opis_no = strlen($opis);
- $date = date('Y-m-d H:i:s');
- // Check if term is alredy in databese
- $result = mysql_query("SELECT * FROM jos_glossary WHERE tterm = '$naziv' LIMIT 1",$conn1) or die(mysql_error($conn1));
- $row = mysql_fetch_row($result);
- if ($row != '') {$check = 'NO';}
- elseif ($row == '') {$check = 'UPDATE';}
- // if not update db
- if ($check == 'UPDATE' and $opis_no > 3)
- {
- echo '<br />- Slovo: '.$slovo.' - Ime: '.$naziv.' Opis : '.$opis.'<br />';
- flush();
- $sql = "INSERT INTO `YOUR_DATABASE_PNAME`.`jos_glossary`
- (
- `tletter`,
- `tterm`,
- `tdefinition`,
- `tdate`,
- `teditdate`,
- `published`,
- `catid`,
- `checked_out`
- ) VALUES (
- '$slovo',
- '$naziv',
- '$opis',
- '$date',
- '$date',
- '1',
- '1',
- '0');";
- mysql_query($sql, $conn1) or die(mysql_error($conn1));
- }
- else {
- $a++;
- } // IF End
- $a++;
- }// While end
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement