Solved

php and accents

Posted on 2013-05-29
8
299 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 51

Expert Comment

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

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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
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…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

708 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

15 Experts available now in Live!

Get 1:1 Help Now