Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

php and accents

Posted on 2013-05-29
8
Medium Priority
?
315 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 1000 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 59

Expert Comment

by:Julian Hansen
ID: 39204057
you need to do a urldecode on the other side
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 59

Assisted Solution

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

Open in new window

0
 
LVL 111

Assisted Solution

by:Ray Paseur
Ray Paseur earned 800 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 111

Assisted Solution

by:Ray Paseur
Ray Paseur earned 800 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

These days socially coordinated efforts have turned into a critical requirement for enterprises.
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.
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…
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.

715 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