homepage Welcome to WebmasterWorld Guest from 54.204.142.143
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
PHP UTF-8 url
zdig1




msg:4183083
 11:43 am on Aug 6, 2010 (gmt 0)

Hello guys,

I'm currently building multilanguage website and I have a strange problem when I try to print messages in another languages. For example, when I get russian translations from MySQL database and trying to print them with PHP, browser shows just "?" instead of the message in russian. and arabic (php melody )

My MySQL tables are UTF-8 by default (character set is set to "UTF-8 Unicode" and collation is set to "utf8_general_ci").

I've googled for it, and found one advice. I've added "mysql_query("SET NAMES utf8");" into my PHP script before other MySQL queries instead of "?" I get a lot of ugly characters in the browser now like "ÐоÐÐвиÑÑŒ мÐсÑо дÐя посÐÑÐния".

I think it's PHP/MySQL problem, not browser or HTML. I wonder how can I fix it?

 

lammert




msg:4183089
 11:57 am on Aug 6, 2010 (gmt 0)

Hi zdig1, first of all Welcome to WebmasterWorld!

Does your webserver send the correct character encoding to the browser? It could be that the HTML is correct, but that the browser is forced to use the wrong encoding type due to invalid headers it receives from the webserver.

zdig1




msg:4183167
 4:22 pm on Aug 6, 2010 (gmt 0)

thx for this great welcome
the probleme is not from server and not from mysql

cause in some page it work
[tunisway.com...]


but not in other
[tunisway.com...]

i use firfox 3.6.8
nad the 1rst url it is in uft-8 cactere ( try to copy it in url adrss bar you will see )

but the second it still on alpha numeric and this is very very bad for seo and for site's member

thx for you help

zdig1




msg:4183641
 4:38 pm on Aug 7, 2010 (gmt 0)

no one of this great froum have idea !

enigma1




msg:4183906
 6:42 pm on Aug 8, 2010 (gmt 0)

you need to perform the set names query before you select the database. Check your scripts what they do right after they connect to the db.

You also need to emit the right http header.

header('Content-Type: text/html; charset=utf-8');

zdig1




msg:4184836
 2:51 pm on Aug 10, 2010 (gmt 0)

plz dont post any thing as answer this probleme is only for PRO webmaster

for the header all is correct as i said ( see the both link one is working nice the other no

enigma1




msg:4185004
 6:38 pm on Aug 10, 2010 (gmt 0)

plz dont post any thing as answer this probleme is only for PRO webmaster

Then perhaps you should ask your questions in private since you know who is pro and who isn't.

zdig1




msg:4185006
 6:46 pm on Aug 10, 2010 (gmt 0)

:p sorry if you take it as a personal but because our site suffring from this probelem and we must sove it very fast
all link look stange and we lost all referecmetn in seo cause it is with stage caracgte 55d45454df54df54df54.html !
[tunisway.com...]
i have this on all my pages

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

[edited by: jatar_k at 4:54 pm (utc) on Aug 11, 2010]
[edit reason] fixed a copy paste error on the url [/edit]

lammert




msg:4185038
 7:38 pm on Aug 10, 2010 (gmt 0)

A meta Content-Type tag has no value, if the webserver where the site is running on sends out another content type in the header lines. Browsers only use the meta tag as a last resort if there is no other way the content type can be determined. The only ways to be sure your server is sending out the correct Content-Type header is either use the header('Content-Type: text/html; charset=utf-8'); PHP statement as enigma1 explained a few posts earlier, or set the correct default Content-Type header in your webserver configuration file.

A quick scan with a server header checker on the example URLs you provided, learns that the server doesn't send the UTF-8 content header by default:

Content-Type: text/html; charset=iso-8859-1

AlexK




msg:4185079
 9:24 pm on Aug 10, 2010 (gmt 0)

@lammert: maybe he's seen your message & already changed it, but *both* pages show `charset=utf-8' for me (Web Developer | Information under FF3.6.8).

I'm uncertain what the precise problem is. The first post *appears* to be a problem with text-on-page, yet *both* pages are fine, as far as I can tell. It seems, therefore, that the issue comes down to the URL itself: zdig1 wants non-ASCII characters within the URL, which has worked with one page (link provided), but not with the other (link also provided).

Using UTF8 in URLs is outside of my direct, personal experience (though I do not think that it will work), but I have an obvious question to ask: does this problem only appear when the non-ASCII part of the URL is a sub-directory name? I ask the question because that is the obvious difference between the two URLs.

Another observation: the working URL is a r-to-l language embedded within a l-to-r language (that is how it appears within my browser when I scroll through it; quite wonderful).

This next bit may offer a work-around whilst you find the actual problem: the `Response headers' page in Web Developer show me the following Titles (I've changed the base-url for `<Base URL>':
Response Headers - <Base URL>/video/tags/%D8%A5%D9%8A%D9%85%D8%A7%D9%86-%D8%A7%D9%84%D8%B7%D9%88%D8%AE%D9%8A/

...whereas the non-working page shows the following:
Response Headers - <Base URL>/video/-d9-85-d8-b3-d9-84-d8-b3-d9-84-d8-b1-d8-a3-d9-81-d8-aa-d8-a7-d9-84-d9-87-d8-ac-d8-a7-d9-86/14-video_178296502.html

(you will understand from this that Web Developer has converted the non-ascii-part to URL-encoded ascii)

I am unsure whether UTF8 URLs are currently supported. I know that plans are laid/already implemented/whatever, but would not be in the least surprised to find that they are poorly supported. The obvious workaround is to convert all your URLs using `htmlentities(urlencode($url-part))' (be careful not to encode the directory separators). The browser will then auto-convert that URL-encoded string back into a readable string within the address bar.

You will need to carefully research the UTF8-support for urlencode(). I believe it to be good in PHP6, but you are using PHP5.2, and it is not so good.

One final thought: is the default language on your server UTF8?

zdig1




msg:4187447
 11:46 pm on Aug 15, 2010 (gmt 0)

thx alex and lamert for your time

does this problem only appear when the non-ASCII part of the URL is a sub-directory name?
yes for other caractere it is a normal link
for utf8 it become alpha numeric

is the default language on your server UTF8?
if you meam sqldatabase and php yes it supporte them


in my ff the 1 srt url even is writen here in alpahnumeric when i open page it change to utf8 word
but the secd link it still as alphanumeric

i become crzay and i disabled seo link feature :):( until i resolve this probelem :(((

zdig1




msg:4187449
 11:55 pm on Aug 15, 2010 (gmt 0)

Line 857: $jw_flashvars .= '&file='. urlencode($video['direct']);
Line 862: $jw_flashvars .= '&file='. urlencode(_URL ."/videos.php?vid=". $video['uniq_id']);
Line 865: $jw_flashvars .= '&config='. urlencode(_URL ."/jwembed.xml");

without seo url look like
[tunisway.com...]

so this mean that probleme on msuicvideo.php file ?

AlexK




msg:4187459
 12:38 am on Aug 16, 2010 (gmt 0)

URLs containing non-ASCII text need to be urlencoded; see here: [uk.php.net...]

You will need to
urlencode() each sub-directory, then htmlentities() the whole thing:

$base='http://www.example.com'
$sub_dir1=urlencode('sub-dir1');
$sub_dir2=urlencode('sub-dir2');
...
$sub_dirn=urlencode('sub-dirn');
$url=htmlentities("$base/$sub_dir1/$sub_dir2/.../$sub_dirn/");

BUT! read through all the comments in the link already given.

And that is only the URL, not the original OP...

rrreee2




msg:4188468
 2:35 am on Aug 18, 2010 (gmt 0)

I dont fully udnerstand you problem but when i print results from databse i use this before the SELECT query.

mysql_query("SET CHARACTER_SET_RESULTS=utf8");

let me know if it helps you, or perhaps your problem was something diffrent

before an INSER query you use mysql_query("SET NAMES 'utf8'");

zdig1




msg:4191202
 12:23 am on Aug 24, 2010 (gmt 0)

i moved to this
Streaming Rakuen
[zdig1.biz...]
try naviagtion on it you will see what i undersatnd
url with utf-8 :((((

AlexK




msg:4191449
 3:20 pm on Aug 24, 2010 (gmt 0)

zdig1: (url for zdig1.biz)

WOT says your site has a poor rep - I'll give it a miss, thanks.

zdig1




msg:4196506
 2:06 pm on Sep 4, 2010 (gmt 0)

!
url is not zdig1.biz but zdig1.biz/video

zdig1




msg:4199221
 10:11 am on Sep 9, 2010 (gmt 0)

hello you can see those 2 pic it will resume the probleme
pic 1: it's for tag link
you can see that both name of page and link are writenin utf-8
[img413.imageshack.us...]

pic2: for video and music it not work anymore
in title page it in utf8 but in link it's on alpha numeric
[img227.imageshack.us...]

so forget database probelme and sql request
i think it's a php code soruce probleme i can post for you code soruce

for many month i hve this problem plz any idea ?

zdig1




msg:4199225
 10:25 am on Sep 9, 2010 (gmt 0)

can this be helpful ?

$voth = make_voth();
$video = request_video($voth, "index");
$voth_title = '<a href="'. makevideolink($video['uniq_id'], $video['artist'], $video['video_title']).'">'. $video['artist'] .' - '. $video['video_title'] .'</a>';



<a href=\"".makevideolink($row['uniq_id'], $row['artist'], $row['video_title'])."\">

[edited by: zdig1 at 10:46 am (utc) on Sep 9, 2010]

zdig1




msg:4199235
 10:34 am on Sep 9, 2010 (gmt 0)

function makevideolink($id, $artist = '', $video_title = '')
{
$r = array();

if (_SEOMOD == 1)
{
if ('' != $artist && '' != $video_title)
{
$r['artist'] = $artist;
$r['video_title'] = $video_title;
}
else
{
$query = @mysql_query("SELECT artist, video_title FROM pm_videos WHERE uniq_id = '".$id."'");
$r = mysql_fetch_array($query);
mysql_free_result($query);
}
$artist = sanitize_title($r['artist']);
$artist = safename($artist);
$song = $r['video_title'];
$song = sanitize_title($song);
$song = safename($song);

$return = _URL .'/'. $artist .'/'. $song .'-video_'. $id .'.html';
}
else
{
$return = _URL .'/musicvideo.php?vid='.$id;
}

return $return;
}

zdig1




msg:4209543
 8:09 pm on Sep 30, 2010 (gmt 0)

i see that is this site it resolve probleme
all arabic film have an arabuc url ( utf-8)
i contacted them but no answer
[amman-dj.com...]

zdig1




msg:4210693
 11:33 am on Oct 3, 2010 (gmt 0)

for tag it work

function get_video_tags($uniq_id = '', $make_links = 1)
{
$sql = "SELECT * FROM pm_tags WHERE uniq_id = '".$uniq_id."' ORDER BY tag_id ASC";
$result = mysql_query($sql);
$tags = array();
$id = 0;
while($row = mysql_fetch_assoc($result))
{
$id = $row['tag_id'];
$tags[$id] = $row;
if($make_links != 0)
{
if(_SEOMOD == 1)
{
$tags[$id]['href'] = "<a href=\""._URL."/tags/".$row['safe_tag']."/\">".$row['tag']."</a>";
}
else
{
$tags[$id]['href'] = "<a href=\""._URL."/tag.php?t=".$row['safe_tag']."\">".$row['tag']."</a>";
}
}
}
return $tags;
}

zdig1




msg:4210697
 11:51 am on Oct 3, 2010 (gmt 0)

i reslove it by my self :))))))))))))))))))))))

thx for all coperation :)))

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved