Solved

php and accents

Posted on 2013-05-29
8
304 Views
Last Modified: 2013-06-02
I have the following GET url:

a href="artistinfo.php?artist=<?php echo $row_thumbs['art_Name']; ?>"

This usually worksd perfectly well but now one of the names has an accented character:
name: Ricardo Galán Urréjola

How can I send this in a GET url (above) so that the url can be used as a search string on the target page and present the correct name with accents

I have tried addslashes etc but no joy


I have tried encoding the characters in the database as: Manuel L&oacute;pez Herrera

This is the presented GET url:
artistinfo.php?artist=Ricardo%20Gal n%20Urr jola (the gaps have a square in them)
0
Comment
Question by:doctorbill
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 4

Accepted Solution

by:
Ahmed Hussein earned 250 total points
ID: 39203977
Do a url encode before sending the paramaters:

a href="artistinfo.php?artist=<?php echo urlencode($row_thumbs['art_Name']); ?>"

and when you receive it in your php code do this urldecode($_GET["artist"]);

That's it.

~AG
0
 

Author Comment

by:doctorbill
ID: 39204044
The url sent is as follows:

artist=Ricardo+Gal%E1n+Urr%E9jola+

Problem is that it is still not recognised. How can I test what this is actually showing to the target page ?
0
 
LVL 52

Expert Comment

by:Julian Hansen
ID: 39204057
you need to do a urldecode on the other side
0
 
LVL 52

Assisted Solution

by:Julian Hansen
Julian Hansen earned 50 total points
ID: 39204059
$artist = isset($_GET['artist'])?urldecode($_GET['artist']):'';
echo $artist;

Open in new window

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 108

Assisted Solution

by:Ray Paseur
Ray Paseur earned 200 total points
ID: 39204142
There are a host of potential issues at work here.  Start your learning adventures about character encoding with this article.
http://www.joelonsoftware.com/articles/Unicode.html

You always want to use URLENCODE() on data that is sent as part of a URL.  However GET variables are automatically passed through URLDECODE().

So step one is to ensure that you have actually got the data you think you have in the $row_thumbs['art_Name'] variable.  Suggestion: use var_dump() to print this out and use your browser "view source" to display the contents of this variable.  You may not have something that is useful if your script has improperly encoded the data in this variable, for example, before putting it into the data base.  phpMyAdmin may be helpful, too.

Your character encoding must be consistent from start to finish.  The reason for this is that the accented characters can be represented by either a single byte in western-european character sets or by a multi-byte character in UTF-8.  Any attempt to compare UTF-8 strings to single-byte ASCII strings is at risk of failure if there is a character above the code point 128(decimal).  A good way of checking for this sort of misalignment is to use strlen() to test the string.  If Galán looks like five characters to your eye when you use "view source" but strlen() reports more than 5 characters, you almost certainly have multi-byte encoding.

See http://www.laprbass.com/RAY_temp_doctorbill.php?q=Ricardo+Galán+Urréjola where the output of the script strongly suggests that this is a UTF-8 string.  However the accented characters can exist in ASCII, too.  Your text editor may or may not recognize UTF-8.

<?php // RAY_temp_doctorbill.php
error_reporting(E_ALL);
echo '<pre>';

// SEE http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_28141498.html
// SEE http://www.laprbass.com/RAY_temp_doctorbill.php?q=Ricardo+Galán+Urréjola

$get = !empty($_GET['q']) ? $_GET['q'] : NULL;
echo PHP_EOL . '1...5...10...15...20...25...30...';
echo PHP_EOL . $get;
echo PHP_EOL . "STRLEN IS " . strlen($get);
echo PHP_EOL;

$url = 'http://www.laprbass.com/RAY_temp_doctorbill.php?q=' . urlencode($get);
echo PHP_EOL . $url;
echo PHP_EOL;

$lnk = '<a href="' . $url . '">' . $url . '</a>';
echo $lnk;

Open in new window

0
 

Author Comment

by:doctorbill
ID: 39204161
Thanks very much - working now
0
 
LVL 108

Assisted Solution

by:Ray Paseur
Ray Paseur earned 200 total points
ID: 39204170
Now see http://www.laprbass.com/RAY_temp_doctorbill.php?q=Ricardo+Gal%E1n+Urr%E9jola where the GET input and the script output shows the same visual letters but the accented characters are single bytes.  Note the difference in string length.

So check your character encoding all the way through the process - from your text editor to your PHP script to your data base storage to your browser output.  These need to be consistent - either an ASCII character set or UTF-8.  The current recommendation is UTF-8, and PHP will make the change to UTF-8 some time soon.

Best of luck with it, and best regards, ~Ray
0
 

Author Closing Comment

by:doctorbill
ID: 39214453
solved
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now