Solved

php and accents

Posted on 2013-05-29
8
314 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 58

Expert Comment

by:Julian Hansen
ID: 39204057
you need to do a urldecode on the other side
0
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
LVL 58

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
 
LVL 110

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 110

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

617 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