Solved

php and accents

Posted on 2013-05-29
8
313 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 57

Expert Comment

by:Julian Hansen
ID: 39204057
you need to do a urldecode on the other side
0
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
LVL 57

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
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…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

710 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