Доброго дня всем. Когда загоняю xml в базу MySql иногда обрезаются строки. Например если есть строка где написано "Петя <Вася> Миша". То в базу записывается только "Миша". Как я понимаю это происходит из за этих символов ( < > ). Но как решить эту проблему не знаю. xml - windows-1251 сайт и MySql - utf-8
PHP: xml_parser_create(); Или весь код выслать? --- Добавлено --- PHP: $filename1 = 'file/Price.xml'; ConnectDB(); $elements = null; // просто имя текущей ноды $offer = null; // собирает один элемент offer $att = null; $att2 = null; categories($filename1); // Вызывается, когда встречается открывающий тег. // если это offer - создаем массив под него function startElements($parser, $name, $attrs) { global $offer, $elements, $att, $att2; if ($name == 'OFFER') { $offer = array(); $att = array($attrs[ID]); $att2 = array($attrs[ORDERBY]); } $elements = $name; } // Вызывается, когда тег закрывается // если это тег offer - печатаем содержимое и вычищаем function endElements($parser, $name) { global $offer, $elements, $att, $att2; global $mysqli; if(!empty($name)) { if ($name == 'OFFER') { //$array12= "$att[ID]"; $oId2 = $att[0]; $oORDERBY = $att2[0]; $oUid= "$offer[UID]"; $oUrl= "$offer[URL]"; $oPriceR= "$offer[PRICER]"; $oPriceB= "$offer[PRICEB]"; $oPriceC= "$offer[PRICEC]"; $oPriceD= "$offer[PRICED]"; $oPriceE= "$offer[PRICEE]"; $oPriceF= "$offer[PRICEF]"; $oPriceRRP = "$offer[PRICERRP]"; $oCurrencyId = "$offer[CURRENCYID]"; $oCategoryId = "$offer[CATEGORYID]"; $oPicture = "$offer[PICTURE]"; $oCount1 = "$offer[COUNT]"; $oName = "$offer[NAME]"; $oWarranty = "$offer[WARRANTY]"; $oPN = "$offer[PN]"; $oTransit = "$offer[TRANSIT]"; $oTransitdate = "$offer[TRANSITDATE]"; $oRemote = "$offer[REMOTE]"; $oVolume = "$offer[VOLUME]"; $oWeight = "$offer[WEIGHT]"; //$oRussianName = str_replace("#38","rer","$offer[RUSSIANNAME]"); //$oRussianName= htmlentities(htmlentities('&', ENT_QUOTES, 'utf-8')); //$oRussianName = preg_replace('&', '', "$offer[RUSSIANNAME]"); $oRussianName="$offer[RUSSIANNAME]"; //$oRussianName=htmlspecialchars_decode("$offer[RUSSIANNAME]"); $oDescrUpDated = "$offer[DESCRUPDATED]"; $oModel = "$offer[MODEL]"; $oVendor = "$offer[VENDOR]"; $oLastCountry = "$offer[LASTCOUNTRY]"; $oLastGTD = "$offer[LASTGTD]"; $oColour = "$offer[COLOUR]"; $oWarrantyType = "$offer[WARRANTYTYPE]"; $oPicture2 = "$offer[PICTURE2]"; $oPicture3 = "$offer[PICTURE3]"; $oOutOffProd = "$offer[OUTOFPROD]"; $oCertificate = "$offer[CERTIFICATE]"; $oGTIN = "$offer[GTIN]"; if ($oId2 == null) $oId2=0; if ($oORDERBY == null) $oORDERBY=0; if ($oUid == null) $oUid=0; if ($oUrl == null) $oUrl='0'; if ($oPriceR == null) $oPriceR=0; if ($oPriceB == null) $oPriceB=0; if ($oPriceC == null) $oPriceC=0; if ($oPriceD == null) $oPriceD=0; if ($oPriceE == null) $oPriceE=0; if ($oPriceF == null) $oPriceF=0; if ($oPriceRRP == null) $oPriceRRP=0; if ($oCurrencyId == null) $oCurrencyId='0'; if ($oCategoryId == null) $oCategoryId=0; if ($oPicture == null) $oPicture='0'; if ($oCount1 == null) $oCount1='0'; if ($oName == null) $oName='0'; if ($oWarranty == null) $oWarranty='0'; if ($oPN == null) $oPN='0'; if ($oTransit == null) $oTransit='0'; if ($oTransitdate == null) $oTransitdate='0'; if ($oRemote == null) $oRemote='0'; if ($oVolume == null) $oVolume=0; if ($oWeight == null) $oWeight=0; if ($oRussianName == null) $oRussianName='0'; if ($oDescrUpDated == null) $oDescrUpDated='0'; if ($oModel == null) $oModel='0'; if ($oVendor == null) $oVendor='0'; if ($oLastCountry == null) $oLastCountry='0'; if ($oLastGTD == null) $oLastGTD='0'; if ($oColour == null) $oColour='0'; if ($oWarrantyType == null) $oWarrantyType='0'; if ($oPicture2 == null) $oPicture2='0'; if ($oPicture3 == null) $oPicture3='0'; if ($oOutOffProd == null) $oOutOffProd='0'; if ($oCertificate == null) $oCertificate='0'; if ($oGTIN == null) $oGTIN='0'; if(iconv_strlen($oRussianName)<22) $oCount1='0';; $mysqli->query("INSERT INTO offer_ (Id2_,OrderBy_, Uid_, Url_, PriceR_, PriceB_, PriceC_, PriceD_, PriceE_, PriceF_, PriceRRP_, CurrencyId_, CategoryId_, Picture_, Count_, Name_, Warranty, PN_, Transit_, Transitdate, Remote_, Volume_, Weigth_, RussianName_, DescrUpDated_, Model_, Vendor_, LastCountry_, LastGTD_, Colour_, WarrantyType_, Picture2_, Picture3_, OutOffProd_, Certificate_, GTIN_) VALUES ($oId2, $oORDERBY, $oUid, '$oUrl', $oPriceR, $oPriceB, $oPriceC, $oPriceD, $oPriceE, $oPriceF, $oPriceRRP, '$oCurrencyId', $oCategoryId, '$oPicture', '$oCount1', '$oName', '$oWarranty', '$oPN', '$oTransit', '$oTransitdate', '$oRemote', $oVolume, $oWeight, '$oRussianName', '$oDescrUpDated', '$oModel', '$oVendor', '$oLastCountry', '$oLastGTD', '$oColour', '$oWarrantyType', '$oPicture2', '$oPicture3', '$oOutOffProd', '$oCertificate', '$oGTIN')"); $offer = null; } $elements = null; } } // Вызывается для текста, заполняем массив function characterData($parser, $data) { global $offer, $elements, $ell; if(!empty($data)) { if ($elements == 'UID' || $elements == 'URL' || $elements == 'PRICER' || $elements == 'PRICEB' || $elements == 'PRICEC' || $elements == 'PRICED' || $elements == 'PRICEE' || $elements == 'PRICEF' || $elements == 'PRICERRP' || $elements == 'CURRENCYID' || $elements == 'CATEGORYID' || $elements == 'PICTURE' || $elements == 'COUNT' || $elements == 'NAME' || $elements == 'WARRANTY' || $elements == 'PN' || $elements == 'TRANSIT' || $elements == 'TRANSITDATE' || $elements == 'REMOTE' || $elements == 'VOLUME' || $elements == 'WEIGHT' || $elements == 'RUSSIANNAME' || $elements == 'DESCRUPDATED' || $elements == 'MODEL' || $elements == 'VENDOR' || $elements == 'LASTCOUNTRY' || $elements == 'LASTGTD' || $elements == 'COLOUR' || $elements == 'WARRANTYTYPE' || $elements == 'PICTURE2' || $elements == 'PICTURE3' || $elements == 'OUTOFPROD' || $elements == 'CERTIFICATE' || $elements == 'GTIN') { $offer[$elements] = trim($data); } } } // Собственно, подготавливаем парсер $parser = xml_parser_create(); xml_set_element_handler($parser, "startElements", "endElements"); xml_set_character_data_handler($parser, "characterData"); // открываем файл if (!($handle = fopen($filename1, "r"))) { die("could not open XML input"); } while($data = fread($handle, 4096)) // читаем по кусочкам { xml_parse($parser, $data); // и стравливаем парсеру } xml_parser_free($parser); // почистим за собой.