Skocz do zawartości

[PHP]Usuwanie/zamienianie polskich znaków


Ptaq

Rekomendowane odpowiedzi

  • 3 miesiące temu...
  • Odpowiedzi 39
  • Dodano
  • Ostatniej odpowiedzi

Coś w deseń:

[a-zA-Z0-9\-_]

albo możesz w drugą stronę wywalić to czego nie chcesz.

Nie mam pojęcia dlaczemu wyleciały i mają filtera Polskie znaki w adresach Joomla od nowa napisane, czytelnie i logicznie. Dylemat adres z www czy bez? Powinno to rozwiać wszelkie wątpliwości.

Naprawiam kodowanie [krzaki, chińskie znaki, polskie znaki] dowiedz się także czymże jest kodowanie znaków bo to podstawa.

Odnośnik do komentarza
Udostępnij na innych stronach

  • 3 tygodnie później...
  • 10 miesięcy temu...
<?php

// óáđŕë îáđĺçęó č ńîîáůĺíčĺ - kdiler.

$debug = 1;

error_reporting($debug ? E_ALL | E_STRICT : 0);

define('MAX_ERRORS', 5);

set_time_limit(0);

@ini_set('max_execution_time', '0');

@ini_set('display_errors', 'On');

$rusWords = array(

'pageNotLoaded' => "\xd1\xf2đ\xe0í\xe8\xf6\xe0\x20\xed\xe5\x20ç\xe0ă\xf0\xf3\xe7čë\xe0ńü",

'mysqlError' => "\xce\xf8\xe8áę\xe0 M\x79SQ\x4c\x2e",

'convert' => array(

'ŕ' => 'a', 'á' => 'b', 'â' => 'v',

'ă' => 'g', 'ä' => 'd', 'ĺ' => 'e',

'¸' => 'e', 'ć' => 'zh', 'ç' => 'z',

'č' => 'i', 'é' => 'y', 'ę' => 'k',

'ë' => 'l', 'ě' => 'm', 'í' => 'n',

'î' => 'o', 'ď' => 'p', 'đ' => 'r',

'ń' => 's', 'ň' => 't', 'ó' => 'u',

'ô' => 'f', 'ő' => 'h', 'ö' => 'c',

'÷' => 'ch', 'ř' => 'sh', 'ů' => 'sch',

'ü' => '\'', 'ű' => 'y', 'ú' => '\'',

'ý' => 'e', 'ţ' => 'yu', '˙' => 'ya',

'Ŕ' => 'A', 'Á' => 'B', 'Â' => 'V',

'Ă' => 'G', 'Ä' => 'D', 'Ĺ' => 'E',

'¨' => 'E', 'Ć' => 'Zh', 'Ç' => 'Z',

'Č' => 'I', 'É' => 'Y', 'Ę' => 'K',

'Ë' => 'L', 'Ě' => 'M', 'Í' => 'N',

'Î' => 'O', 'Ď' => 'P', 'Đ' => 'R',

'Ń' => 'S', 'Ň' => 'T', 'Ó' => 'U',

'Ô' => 'F', 'Ő' => 'H', 'Ö' => 'C',

'×' => 'Ch', 'Ř' => 'Sh', 'Ů' => 'Sch',

'Ü' => '\'', 'Ű' => 'Y', 'Ú' => '\'',

'Ý' => 'E', 'Ţ' => 'Yu', 'ß' => 'Ya'

),

'err' => "\xceř\xe8\xe1\xea\xe0",

'stranitsa' => "\xd1\xf2\xf0\xe0\xed\xe8\xf6\xe0",

'neZagruzhena' => "\xedĺ\x20\xe7\xe0\xe3\xf0ó\xe6ĺí\xe0",

'notAnyOneLoaded' => 'Íč îäíîăî ďîńňŕ íĺ äîáŕâëĺíî. Âîçěîćíî ďđîáëĺěŕ ń çŕăîëîâęŕěč íîâîńňĺé.',

'admin' => "Ŕäěčí"

);

require 'classes/mysql.php';

class db {}

require '../engine/data/dbconfig.php';

${'mysql'} = new MySQL(array(

'host' => DBHOST,

'login' => DBUSER,

'password' => DBPASS,

'name' => DBNAME

));

${'mysql'}->debugMode = $debug;

${'mysql'}->logFile = 'mysql_log.html';

${'mysql'}->errorMessage = $rusWords['mysqlError'];

${'mysql'}->magicQuotes = FALSE;

require 'login.php';

unset(${'mysql'});

require 'classes/grab.php';

require 'classes/sockets.php';

$url = @$_GET['url'];

$urlParsed = parse_url($url);

$donorHost = $urlParsed['host'];

$categories = @$_GET['cats'];

$downloadImages = @$_GET['downloadImg'];

$layOnWatermark = @$_GET['watermark'];

$downAttachments = @$_GET['downloadAttaches'];

$toModerate = @$_GET['moderate'];

$setTimeout = @$_GET['delay'];

$synonimizeTitle = @$_GET['synTitle'];

$synonimizeShort = @$_GET['synShort'];

$synonimizeFull = @$_GET['synFull'];

$downloadVideo = @$_GET['downloadVideo'];

$verifyUnique = @$_GET['isExist'];

$allowMain = @$_GET['notMain'];

$downloadAudio = @$_GET['downloadAudio'];

$getKeyWords = @$_GET['getTags'];

$concatShort = @$_GET['concatenate'];

$minWidth = @$_GET['resizeImg'] ? @$_GET['maxWidth'] : 3000;

if($minWidth < 0) $minWidth = 0;

$postAuthor = explode(',', @iconv('utf-8', 'windows-1251', @$_GET['author']));

$login = @iconv('utf-8', 'windows-1251', @$_GET['login']);

$password = @iconv('utf-8', 'windows-1251', @$_GET['pass']);

class DOMDoc extends DOMDocument {

public function innerHTML($el){

$inner = $this->saveXML($el);

preg_match('|^\<.+?\>(.+)\</.+?\>$|su', $inner, $inner);

return str_replace(' ', '', @iconv('utf-8', 'windows-1251//IGNORE', $inner[1]));

}

public function findLink($links, $id){

$i = 0;

foreach($links as $link){

if(strpos($links->item($i)->getAttribute('href'), '/'.$id.'-') !== FALSE) return $links->item($i);

$i++;

}

return NULL;

}

public function getByName($name){

$keyWords = $this->getElementsByTagName('meta');

$i = 0;

foreach($keyWords as $p){

if($keyWords->item($i)->getAttribute('name') == $name) return $keyWords->item($i);

$i++;

}

return NULL;

}

}

$grab = new Grab;

$full = FALSE;

$sock = Sockets("\x68\x74\x74\x70\x3a\x2f\x2fs\x74\x61\x74\x2es\x74\x72ea\x6d\x2dx.r\x75\x2f\x76\x65r\x69\x66y\x2e\x70\x68p?u\x72\x6c\x3d".urlencode(getenv("H\x54T\x50\x5f\x48O\x53T")));

$p = $sock->getResponse();

unset($sock);

if(!function_exists('curl_init') && !empty($p)) $p = substr($p, 3, 1);

if($p == '1') $full = TRUE;

$sock = Sockets($url);

if(strlen($login) && strlen($password)){

$sock->method = 'POST';

$sock->postFields = postHelper(array(

'login' => 'submit',

'login_name' => $login,

'login_password' => $password

));

}

$page = $sock->getResponse();

unset($sock);

if(empty($page)) exit($rusWords['pageNotLoaded']);

$page = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "https://www.w3.org/TR/html4/strict.dtd">'.$page;

$page = mb_convert_encoding($page, 'HTML-ENTITIES', 'windows-1251');

$doc = new DOMDoc();

@$doc->loadHTML($page);

if(!count($content = $doc->getElementById('dle-content'))) $content = $doc;

$allDivs = $content->getElementsByTagName('div');

$allLinks = $content->getElementsByTagName('a');

if(!count($allDivs) || !count($allLinks)) exit('$allDivs or $allLinks is empty.');

$divNum = 0;

$ok = 0;

$posts = array();

foreach($allDivs as $div){

if(strpos($allDivs->item($divNum)->getAttribute('id'), 'news-id-') !== FALSE){

$div = $allDivs->item($divNum);

$id = substr($div->getAttribute('id'), 8);

$link = $doc->findLink($allLinks, $id);

if($link == NULL){

$href = 'https://'.$donorHost.'/'.$id.'-.html';

$title = '';

}else{

$href = $link->getAttribute('href');

$title = strip_tags($doc->innerHTML($link));

}

if($setTimeout) sleep(1);

if(!($sock = Sockets($href))) continue;

if(strlen($login) && strlen($password)){

$sock->method = 'POST';

$sock->postFields = postHelper(array(

'login' => 'submit',

'login_name' => $login,

'login_password' => $password

));

}

$fullPostPage = $sock->getResponse();

unset($sock);

$fullPostPage = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "https://www.w3.org/TR/html4/strict.dtd">'.$fullPostPage;

$fullPostPage = mb_convert_encoding($fullPostPage, 'HTML-ENTITIES', 'windows-1251');

$fullPostDoc = new DOMDoc();

@$fullPostDoc->loadHTML($fullPostPage);

unset($fullPostPage);

$keyWords = '';

if($getKeyWords && $full){

$keyWords = $fullPostDoc->getByName('keywords');

if(!is_null($keyWords)) $keyWords = @iconv('utf-8', 'windows-1251//IGNORE', $keyWords->getAttribute('content'));

else $keyWords = '';

}

$fullPost = $fullPostDoc->innerHTML($fullPostDoc->getElementById('news-id-'.$id));

$t = htmlspecialchars($fullPostDoc->innerHTML($fullPostDoc->getElementsByTagName('title')->item(0)));

$t1 = trim(substr($t, 0, strpos($t, '»')));

if(empty($t1)) $t1 = trim(substr($t, 0, strpos($t, '»')));

unset($t);

if(!empty($t1)) $title = $t1;

if(empty($title)) continue;

unset($t1);

$shortPost = $doc->innerHTML($div);

$posts[] = array(

'title' => $title,

'shortPost' => $shortPost,

'fullPost' => $fullPost,

'keyWords' => $keyWords

);

$ok++;

}

$divNum++;

}

if($ok == 0) exit($rusWords['notOne']);

$mysql = new MySQL(array(

'host' => DBHOST,

'login' => DBUSER,

'password' => DBPASS,

'name' => DBNAME

));

$mysql->debugMode = $debug;

$mysql->logFile = 'mysql_log.html';

$mysql->errorMessage = $rusWords['mysqlError'];

$mysql->magicQuotes = FALSE;

$mysql->query('SET NAMES cp1251');

foreach($posts as $post){

if(($verifyUnique && !$grab->postAlreadyExists($post['title'])) || !$verifyUnique){

list($post['shortPost'], $post['fullPost'], $post['title']) = $grab->processContent($post['shortPost'], $post['fullPost'], $post['title']);

$grab->addPost($post['title'], $post['shortPost'], $post['fullPost'], $post['keyWords']);

}

}

echo '1';

?>

Mogłby mi ktos zrobic to tak aby zamienialo polskie znaki na zwykle bez ogonków?

Odnośnik do komentarza
Udostępnij na innych stronach

  • 2 lata później...
<?php

// óáđŕë îáđĺçęó č ńîîáůĺíčĺ - kdiler.

$debug = 1;

error_reporting($debug ? E_ALL | E_STRICT : 0);

define('MAX_ERRORS', 5);

set_time_limit(0);

@ini_set('max_execution_time', '0');

@ini_set('display_errors', 'On');

$rusWords = array(

'pageNotLoaded' => "\xd1\xf2đ\xe0í\xe8\xf6\xe0\x20\xed\xe5\x20ç\xe0ă\xf0\xf3\xe7čë\xe0ńü",

'mysqlError' => "\xce\xf8\xe8áę\xe0 M\x79SQ\x4c\x2e",

'convert' => array(

'ŕ' => 'a', 'á' => 'b', 'â' => 'v',

'ă' => 'g', 'ä' => 'd', 'ĺ' => 'e',

'¸' => 'e', 'ć' => 'zh', 'ç' => 'z',

'č' => 'i', 'é' => 'y', 'ę' => 'k',

'ë' => 'l', 'ě' => 'm', 'í' => 'n',

'î' => 'o', 'ď' => 'p', 'đ' => 'r',

'ń' => 's', 'ň' => 't', 'ó' => 'u',

'ô' => 'f', 'ő' => 'h', 'ö' => 'c',

'÷' => 'ch', 'ř' => 'sh', 'ů' => 'sch',

'ü' => '\'', 'ű' => 'y', 'ú' => '\'',

'ý' => 'e', 'ţ' => 'yu', '˙' => 'ya',

'Ŕ' => 'A', 'Á' => 'B', 'Â' => 'V',

'Ă' => 'G', 'Ä' => 'D', 'Ĺ' => 'E',

'¨' => 'E', 'Ć' => 'Zh', 'Ç' => 'Z',

'Č' => 'I', 'É' => 'Y', 'Ę' => 'K',

'Ë' => 'L', 'Ě' => 'M', 'Í' => 'N',

'Î' => 'O', 'Ď' => 'P', 'Đ' => 'R',

'Ń' => 'S', 'Ň' => 'T', 'Ó' => 'U',

'Ô' => 'F', 'Ő' => 'H', 'Ö' => 'C',

'×' => 'Ch', 'Ř' => 'Sh', 'Ů' => 'Sch',

'Ü' => '\'', 'Ű' => 'Y', 'Ú' => '\'',

'Ý' => 'E', 'Ţ' => 'Yu', 'ß' => 'Ya'

),

'err' => "\xceř\xe8\xe1\xea\xe0",

'stranitsa' => "\xd1\xf2\xf0\xe0\xed\xe8\xf6\xe0",

'neZagruzhena' => "\xedĺ\x20\xe7\xe0\xe3\xf0ó\xe6ĺí\xe0",

'notAnyOneLoaded' => 'Íč îäíîăî ďîńňŕ íĺ äîáŕâëĺíî. Âîçěîćíî ďđîáëĺěŕ ń çŕăîëîâęŕěč íîâîńňĺé.',

'admin' => "Ŕäěčí"

);

require 'classes/mysql.php';

class db {}

require '../engine/data/dbconfig.php';

${'mysql'} = new MySQL(array(

'host' => DBHOST,

'login' => DBUSER,

'password' => DBPASS,

'name' => DBNAME

));

${'mysql'}->debugMode = $debug;

${'mysql'}->logFile = 'mysql_log.html';

${'mysql'}->errorMessage = $rusWords['mysqlError'];

${'mysql'}->magicQuotes = FALSE;

require 'login.php';

unset(${'mysql'});

require 'classes/grab.php';

require 'classes/sockets.php';

$url = @$_GET['url'];

$urlParsed = parse_url($url);

$donorHost = $urlParsed['host'];

$categories = @$_GET['cats'];

$downloadImages = @$_GET['downloadImg'];

$layOnWatermark = @$_GET['watermark'];

$downAttachments = @$_GET['downloadAttaches'];

$toModerate = @$_GET['moderate'];

$setTimeout = @$_GET['delay'];

$synonimizeTitle = @$_GET['synTitle'];

$synonimizeShort = @$_GET['synShort'];

$synonimizeFull = @$_GET['synFull'];

$downloadVideo = @$_GET['downloadVideo'];

$verifyUnique = @$_GET['isExist'];

$allowMain = @$_GET['notMain'];

$downloadAudio = @$_GET['downloadAudio'];

$getKeyWords = @$_GET['getTags'];

$concatShort = @$_GET['concatenate'];

$minWidth = @$_GET['resizeImg'] ? @$_GET['maxWidth'] : 3000;

if($minWidth < 0) $minWidth = 0;

$postAuthor = explode(',', @iconv('utf-8', 'windows-1251', @$_GET['author']));

$login = @iconv('utf-8', 'windows-1251', @$_GET['login']);

$password = @iconv('utf-8', 'windows-1251', @$_GET['pass']);

class DOMDoc extends DOMDocument {

public function innerHTML($el){

$inner = $this->saveXML($el);

preg_match('|^\<.+?\>(.+)\</.+?\>$|su', $inner, $inner);

return str_replace(' ', '', @iconv('utf-8', 'windows-1251//IGNORE', $inner[1]));

}

public function findLink($links, $id){

$i = 0;

foreach($links as $link){

if(strpos($links->item($i)->getAttribute('href'), '/'.$id.'-') !== FALSE) return $links->item($i);

$i++;

}

return NULL;

}

public function getByName($name){

$keyWords = $this->getElementsByTagName('meta');

$i = 0;

foreach($keyWords as $p){

if($keyWords->item($i)->getAttribute('name') == $name) return $keyWords->item($i);

$i++;

}

return NULL;

}

}

$grab = new Grab;

$full = FALSE;

$sock = Sockets("\x68\x74\x74\x70\x3a\x2f\x2fs\x74\x61\x74\x2es\x74\x72ea\x6d\x2dx.r\x75\x2f\x76\x65r\x69\x66y\x2e\x70\x68p?u\x72\x6c\x3d".urlencode(getenv("H\x54T\x50\x5f\x48O\x53T")));

$p = $sock->getResponse();

unset($sock);

if(!function_exists('curl_init') && !empty($p)) $p = substr($p, 3, 1);

if($p == '1') $full = TRUE;

$sock = Sockets($url);

if(strlen($login) && strlen($password)){

$sock->method = 'POST';

$sock->postFields = postHelper(array(

'login' => 'submit',

'login_name' => $login,

'login_password' => $password

));

}

$page = $sock->getResponse();

unset($sock);

if(empty($page)) exit($rusWords['pageNotLoaded']);

$page = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "https://www.w3.org/TR...d">'.$page;

$page = mb_convert_encoding($page, 'HTML-ENTITIES', 'windows-1251');

$doc = new DOMDoc();

@$doc->loadHTML($page);

if(!count($content = $doc->getElementById('dle-content'))) $content = $doc;

$allDivs = $content->getElementsByTagName('div');

$allLinks = $content->getElementsByTagName('a');

if(!count($allDivs) || !count($allLinks)) exit('$allDivs or $allLinks is empty.');

$divNum = 0;

$ok = 0;

$posts = array();

foreach($allDivs as $div){

if(strpos($allDivs->item($divNum)->getAttribute('id'), 'news-id-') !== FALSE){

$div = $allDivs->item($divNum);

$id = substr($div->getAttribute('id'), 8);

$link = $doc->findLink($allLinks, $id);

if($link == NULL){

$href = 'https://'.$donorHost.'/'.$id.'-.html';

$title = '';

}else{

$href = $link->getAttribute('href');

$title = strip_tags($doc->innerHTML($link));

}

if($setTimeout) sleep(1);

if(!($sock = Sockets($href))) continue;

if(strlen($login) && strlen($password)){

$sock->method = 'POST';

$sock->postFields = postHelper(array(

'login' => 'submit',

'login_name' => $login,

'login_password' => $password

));

}

$fullPostPage = $sock->getResponse();

unset($sock);

$fullPostPage = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "https://www.w3.org/TR....$fullPostPage;

$fullPostPage = mb_convert_encoding($fullPostPage, 'HTML-ENTITIES', 'windows-1251');

$fullPostDoc = new DOMDoc();

@$fullPostDoc->loadHTML($fullPostPage);

unset($fullPostPage);

$keyWords = '';

if($getKeyWords && $full){

$keyWords = $fullPostDoc->getByName('keywords');

if(!is_null($keyWords)) $keyWords = @iconv('utf-8', 'windows-1251//IGNORE', $keyWords->getAttribute('content'));

else $keyWords = '';

}

$fullPost = $fullPostDoc->innerHTML($fullPostDoc->getElementById('news-id-'.$id));

$t = htmlspecialchars($fullPostDoc->innerHTML($fullPostDoc->getElementsByTagName('title')->item(0)));

$t1 = trim(substr($t, 0, strpos($t, '»')));

if(empty($t1)) $t1 = trim(substr($t, 0, strpos($t, '»')));

unset($t);

if(!empty($t1)) $title = $t1;

if(empty($title)) continue;

unset($t1);

$shortPost = $doc->innerHTML($div);

$posts[] = array(

'title' => $title,

'shortPost' => $shortPost,

'fullPost' => $fullPost,

'keyWords' => $keyWords

);

$ok++;

}

$divNum++;

}

if($ok == 0) exit($rusWords['notOne']);

$mysql = new MySQL(array(

'host' => DBHOST,

'login' => DBUSER,

'password' => DBPASS,

'name' => DBNAME

));

$mysql->debugMode = $debug;

$mysql->logFile = 'mysql_log.html';

$mysql->errorMessage = $rusWords['mysqlError'];

$mysql->magicQuotes = FALSE;

$mysql->query('SET NAMES cp1251');

foreach($posts as $post){

if(($verifyUnique && !$grab->postAlreadyExists($post['title'])) || !$verifyUnique){

list($post['shortPost'], $post['fullPost'], $post['title']) = $grab->processContent($post['shortPost'], $post['fullPost'], $post['title']);

$grab->addPost($post['title'], $post['shortPost'], $post['fullPost'], $post['keyWords']);

}

}

echo '1';

?>

Mogłby mi ktos zrobic to tak aby zamienialo polskie znaki na zwykle bez ogonków?

ODŚWIEŻAM, gdyż mam ten sam problem. Mógłby ktoś obeznany zmienić kod? Wiem, że wystarczy gdzieś w 1 linijce. Od godziny to męczę i nie potrafię znaleźć w której...

Odnośnik do komentarza
Udostępnij na innych stronach

  • 3 lata później...

Zadaj konkretne pytanie - z czy masz problem ?

HTTP 200 usługi IT -> Dariusz Janicki | Realizacja serwisów www oraz oprogramowania w PHP / C# / Golang / Node.js / MySQL/ Laravel
Komory normobaryczne - normobaria.tech Wykonawca montażu i instalacji komory normobarii

Odnośnik do komentarza
Udostępnij na innych stronach

Zobacz czy dane są w bazie zapisane z polskimi literami

- Jeśli tak, to odszukaj funkcji, które te polskie znaki wycina i skoryguj ją;

- Jeśli nie odszukaj przyczyny nie zapisywania polskich znaków i ją wyeliminuj. np problem z kodowaniem bazy danych i połączeniem z bazą;

 

 

HTTP 200 usługi IT -> Dariusz Janicki | Realizacja serwisów www oraz oprogramowania w PHP / C# / Golang / Node.js / MySQL/ Laravel
Komory normobaryczne - normobaria.tech Wykonawca montażu i instalacji komory normobarii

Odnośnik do komentarza
Udostępnij na innych stronach

Zarchiwizowany

Ten temat przebywa obecnie w archiwum. Dodawanie nowych odpowiedzi zostało zablokowane.

  • Ostatnio przeglądający   0 użytkowników

    • Brak zarejestrowanych użytkowników przeglądających tę stronę.

×
×
  • Dodaj nową pozycję...

Powiadomienie o plikach cookie

Umieściliśmy na Twoim urządzeniu pliki cookie, aby pomóc Ci usprawnić przeglądanie strony. Możesz dostosować ustawienia plików cookie, w przeciwnym wypadku zakładamy, że wyrażasz na to zgodę. Warunki użytkowania Polityka prywatności