Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Strange Char in my string. " Â "
Old 05-01-2010, 10:30 AM Strange Char in my string. " Â "
lynxus's Avatar
Awesomeo-Maximo

Posts: 1,618
Location: UK
Trades: 1
Hi Guys,

Whenever i post the value £ to a mysql database it seems to store it as £

the table is :
utf8_unicode_ci

( So i can have other languages in it )

I cant seem to get rid of this **** char.
Ive tried using str_replace. But that fails.


Whats going on? Any idea where its coming from?

Thanks
G
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


lynxus is offline
Reply With Quote
View Public Profile Visit lynxus's homepage!
 
 
Register now for full access!
Old 05-01-2010, 10:39 AM Re: Strange Char in my string. " Â "
lynxus's Avatar
Awesomeo-Maximo

Posts: 1,618
Location: UK
Trades: 1
I think its an encoding issue.

Still no closer to figuring out how to resolve it tho
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


lynxus is offline
Reply With Quote
View Public Profile Visit lynxus's homepage!
 
Old 05-01-2010, 10:40 AM Re: Strange Char in my string. " Â "
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,384
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
What are you using to display the field?
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 05-01-2010, 10:45 AM Re: Strange Char in my string. " Â "
lynxus's Avatar
Awesomeo-Maximo

Posts: 1,618
Location: UK
Trades: 1
It grabs it from the database.
The value in the DB is £

The page displaying it has charset utf-8

and the page that sends it to the DB is set to utf-8 also
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


lynxus is offline
Reply With Quote
View Public Profile Visit lynxus's homepage!
 
Old 05-01-2010, 10:54 AM Re: Strange Char in my string. " Â "
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,384
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
print out the unicode values that are being stored and retrieved to debug where the problem is occuring.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 05-01-2010, 10:56 AM Re: Strange Char in my string. " Â "
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
Try decoding the data after pulling it from the database

PHP Code:
echo utf8_decode('£'); 
Output:
Code:
£
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 05-01-2010, 10:58 AM Re: Strange Char in my string. " Â "
lynxus's Avatar
Awesomeo-Maximo

Posts: 1,618
Location: UK
Trades: 1
This is SOOO odd.

Decoding it still shows its as the two odd chars.

It send it the DB as '£' However the DB inputs it as A£
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


lynxus is offline
Reply With Quote
View Public Profile Visit lynxus's homepage!
 
Old 05-01-2010, 11:01 AM Re: Strange Char in my string. " Â "
lynxus's Avatar
Awesomeo-Maximo

Posts: 1,618
Location: UK
Trades: 1
Ah ha.

Ive put the decode in the "input" part.

$message = utf8_decode($message);

I just wonder if thats gonna break any translation it currently does for other languages...

using
$message = utf8_decode($message);

when it retrives the data still shows the A£
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


lynxus is offline
Reply With Quote
View Public Profile Visit lynxus's homepage!
 
Old 05-01-2010, 11:02 AM Re: Strange Char in my string. " Â "
lynxus's Avatar
Awesomeo-Maximo

Posts: 1,618
Location: UK
Trades: 1
****,
Yeah it breaks other unicode chars ( im assuming cos its decoded before entry to the DB )
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


lynxus is offline
Reply With Quote
View Public Profile Visit lynxus's homepage!
 
Old 05-01-2010, 11:08 AM Re: Strange Char in my string. " Â "
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,384
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Are they being stored as four bytes each (00 C2 00 A3) in the database?
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 05-01-2010, 11:11 AM Re: Strange Char in my string. " Â "
lynxus's Avatar
Awesomeo-Maximo

Posts: 1,618
Location: UK
Trades: 1
Quote:
Originally Posted by chrishirst View Post
Are they being stored as four bytes each (00 C2 00 A3) in the database?
How do i show that mate?
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


lynxus is offline
Reply With Quote
View Public Profile Visit lynxus's homepage!
 
Old 05-01-2010, 11:33 AM Re: Strange Char in my string. " Â "
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,384
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Echo out the character values in the string.
http://www.php.net/manual/en/function.chr.php
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 05-02-2010, 07:52 AM Re: Strange Char in my string. " Â "
lynxus's Avatar
Awesomeo-Maximo

Posts: 1,618
Location: UK
Trades: 1
Ive found the issue,

Its the htmlentities function.

Grrr
I dont know how to get round this...
I want to be able to display html code ( so it doesnt get run ) but if i take htmlentities out everything is fine.

Any ideas how i can use htmlentities and still retain the correct encoding?
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


lynxus is offline
Reply With Quote
View Public Profile Visit lynxus's homepage!
 
Old 05-02-2010, 07:54 AM Re: Strange Char in my string. " Â "
lynxus's Avatar
Awesomeo-Maximo

Posts: 1,618
Location: UK
Trades: 1
Ah ha!

found i should be using htmlspecialchars instead.

This seems to retain the utf-8 encoding.
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


lynxus is offline
Reply With Quote
View Public Profile Visit lynxus's homepage!
 
Old 05-02-2010, 08:02 AM Re: Strange Char in my string. " Â "
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,384
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Something like -> http://www.webmaster-talk.com/html-f...tml#post294819 <- then
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 05-02-2010, 08:14 AM Re: Strange Char in my string. " Â "
lynxus's Avatar
Awesomeo-Maximo

Posts: 1,618
Location: UK
Trades: 1
Yarp

All sorted now,
I found that using htmlentities is apparently not recommended anymore ( cant find WHY but people say using htmlspecialchars is faster (doubt you could notice ))

Anyway.
i didnt put in the UTF-8 field in htmlentities and that broke it, However im using htmlspecialchars now and it seems to work fine


It was killing my brain as if i outputted the data directly to the page it would show fine, So i figured something has to be wrong with my code / sanity checking as the html page itself was fine and the DB was fine.

I hate issues like this lol.

TY yall. Another mystery solved
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


lynxus is offline
Reply With Quote
View Public Profile Visit lynxus's homepage!
 
Reply     « Reply to Strange Char in my string. " Â "
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.49285 seconds with 12 queries