duanang58939 2012-03-04 15:39
浏览 74

在phpmyadmin或使用php时,mysql数据库中的文本字段中的文本在特殊字符和减号上被截断

Text from text field in mysql database getting cut off on special chars and minus signs when in phpmyadmin or using php.

Hi again there are a few questions relating to this sort of thing however no real definitive answers. I have always had headaches when dealing with text fields that hold descriptions of say 1000-5000 chars now the length is not the issue is is the various chars that people use I had a big issue recently with minus signs cutting off the text on CSV upload so I replaced these with hypens I didn't even know there was a difference and cannot reproduce the different chars with my own keyboard! I thought they had all gone however to my horror I am now working with an XML feed that I will be using to populate a remote website with the details within these descriptions and naturally I get this error

XML Parsing Error: not well-formed Location:
http://www.website.com/clients/clientname/xml/ownwebsite.xml????
Line Number 569, Column 18:2.
Metro Station &#034
------------------^

Now when I look in the actually xml file the full description is there like so...

 <description><![CDATA[Fantastic apartment available for viewing!
    Rooms: 2 Bed + Maids Room
    Bath: 2.5 
    Area: 2000 Sq. Ft.
    Fully Furnished!!
    Right Side
    View: Marina View
    Access to gym, parking, bar and the beach


    For more information or viewing, please call: 12345678910
    Nearby:
    1.  Dubai College - 5minutes
    2.  Nakheel Metro Station - 5 minutes
    3.  Mall of Emirates - 10minutes
    4.  Eternity Medicine Institute(Hospital) - 9 minutes
    5.  Dubai Airport - 33 minutes
    6.  Beach - Walking Distance





 The 20 Shoreline Apartment buildings that line the east side of The
        Trunk features some of the Middle East<br/><br/>In the
        trunk, beautiful affordable 4 bed room, 3 bed     room , 2 bed room
        and 1 bed room Apartments are offered with all modern amenities.    
        You can enjoy the convenience of world class entertainment, dining and
        shopping with majestic oceans views.


Rooms
- Stunning water views
- Ceramic floor tiles
- Solid core entry door with security view hole
- Walk in closest with shelves
- Insulated and double glazed windows
- Tiled balconies
- Overhead lighting

Kitchen

- Highest quality kitchen cabinetry
- Ceramic floor tiles
- Ceramic tiled splash backs
- Selected granite tops
- Twin bowl stainless steel sink with quality mixer tap
- Space and services provided for major appliances
- Track lighting

Bathroom

- Quality vanities with Granite tops
- Ceramic tiled flooring and walls
- Ceramic sanitary ware with matching accessories
- High mirrors and vanity lighting
- Ceramic accessory package to match bathroom design
- Safety glass shower enclosures
- High quality mixer taps

Technology & Security

- High-speed internet access with &#149;future technology-ready&#149; features
- Apartments ready for cable TV and telephones
- Apartments ready for state of the art security system
- High quality switches and outlets
- Security Guard/ Janitor in each building

External Features & Palm Services

- Large underground Parking facilities
- Gardens and Landscape maintained by The Palm

Shoreline Apartments Health And Recreation Clubs

- 5 Health Clubs ( 1 for 4 apartments blocks)
- Access to Clubs for a nominal fee
- All located along the seashore
- All managed by The Palm including pool maintenance
- All with Ground + 1 Floor
- All with Large Swimming Pool
- All with Modern Gym
- All with Children's playground
- All with Restaurants<br/><br/> (unit description)
For more information or viewing, please call: 00971 4 450 8666
Nearby:
1.  School - 
2.  Metro Station �&#034 
3.  Shopping Mall �&#034 
4.  Hospital �&#034 
5.  Dubai Airport �&#034 
6.  Beach �&#034
    Mortgage (available or not)
    Rental yield:
( tower description and all facilities)
Facilities and amenities like: Balcony - Lobby in the building - double glazed windows - Central AC - waste disposal - 7Floors in the building - has 3 elevators - parking space - 24 hour concierge - internet connection - satellite connection - gym or health club - 24 hour security.
(area description and all facilities and amenities)
Our working hours are:
From Saturday to Thursday 8:30 AM to 8:00 PM
To have more information regarding this property, please call our customer service helpdesk on 00971 4 450 8666 or send us an email; info@apex-brokers.com
To find similar properties you can visit our website: www.apex-brokers.com  
For after office working hours, weekend or holidays please call on: 00971 50 917 4500
LIST YOUR RESIDENTIAL OR COMMERCIAL PROPERTY WITH US,
WE HAVE READY CASH BUYERS AND TENANTS LOOKING FOR THE PROPERTIES IN
    Emirates hills, Palm Jumeirah, Al Barari, Jumeirah Island, Arabian Ranches, The Villa, Victory Heights, Hattan, Meadows, The Lakes, The Springs, Jumeirah Park, Jumeirah, Dubai Marina, Jumeirah Beach Residence(JBR), Downtown, Business Bay, The Greens, The Views, Jumeirah Lakes Tower (JLT), Tecom, Al Barsha
    ]]></description>

Yet when in phpmyadmin or echoed in php I only get...

Fantastic apartment available for viewing! Rooms: 2 Bed + Maids Room Bath: 2.5  Area: 2000 Sq. Ft. Fully Furnished!! Right Side View: Marina View Access to gym, parking, bar and the beach


For more information or viewing, please call: 12345678910 Nearby:
1.  Dubai College - 5minutes
2.  Nakheel Metro Station - 5 minutes
3.  Mall of Emirates - 10minutes
4.  Eternity Medicine Institute(Hospital) - 9 minutes
5.  Dubai Airport - 33 minutes
6.  Beach - Walking Distance    
The 20 Shoreline Apartment buildings that line the east side of The Trunk feature some of the Middle East

So the aim of this question really is does anyone have a sure fire way of solving 99% of these stupid character issues in php and XML at the moment I just run this on the string in php before writing to XML and it seems to get most things ok but obviously not all aswell as using CDATA tags that are fairly ineffective at what they are supposed to do!

function cleanstrings($string, $field, $rw){
$string = $rw[$field];
$string = ereg_replace(8220,"&#034",$string);
$string = ereg_replace(8221,"&#034",$string);
$string = ereg_replace(147,"&#034",$string);
$string = ereg_replace(148,"&#034",$string);
$string = ereg_replace(8216, "&#039;", $string); // left single quote
$string = ereg_replace(145, "&#039;", $string); // left single quote
$string = ereg_replace(8217, "&#039;", $string); // right single quote
$string = ereg_replace(146, "&#039;", $string); // right single quote
$string = ereg_replace(8226, "&#149;", $string); // bullet
$string = ereg_replace(149, "&#149;", $string); // bullet
$string = ereg_replace(8211, "&#150;", $string); // en dash
$string = ereg_replace(150, "&#150;", $string); // en dash
$string = ereg_replace(8212, "&#151;", $string); // em dash
$string = ereg_replace(151, "&#151;", $string); // em dash
$string = ereg_replace(8482, "&#153;", $string); // trademark
$string = ereg_replace(153, "&#153;", $string); // trademark
$string = ereg_replace(169, "&copy;", $string); // copyright mark
$string = ereg_replace(174, "&reg;", $string); // registration mark
return $string;
}

Thanks in advance for any help I am sure other people must come across this issue regularly!

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
    • ¥30 深度学习,前后端连接
    • ¥15 孟德尔随机化结果不一致
    • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
    • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
    • ¥15 谁有desed数据集呀
    • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
    • ¥15 关于#hadoop#的问题
    • ¥15 (标签-Python|关键词-socket)
    • ¥15 keil里为什么main.c定义的函数在it.c调用不了