Sorry for the multipost - I forgot to crosspost and alt.php gets less
attention than comp.lang.php.. . And I hope this will work with UTF-8.
In order to make strings suitable for URLs in a UTF-8 encoded website, I use
2 functions, the first of which removes accents from some Latin-1, Latin-2,
and Turkish characters (suggestions for changes or additions welcome!), and
the second removes non-word characters by spaces and then urlencode()s the
string:
function remove_accents( $string, $german=false) {
// Single characters
$single_fr = explode(" ", "À Á Â Ã Ä Å A A Ç C C D D Ð È É Ê Ë E E G Ì Í
Î Ï I L L L Ñ N N Ò Ó Ô Õ Ö Ø O R R S S S T T Ù Ú Û Ü U U Ý Z Z Z à á â ã ä
å a a ç c c d d è é ê ë e e g ì í î ï i l l l ñ n n ð ò ó ô õ ö ø o r r s s
s t t ù ú û ü u u ý ÿ z z z");
$single_to = explode(" ", "A A A A A A A A C C C D D D E E E E E E G I I
I I I L L L N N N O O O O O O O R R S S S T T U U U U U U Y Z Z Z a a a a a
a a a c c c d d e e e e e e g i i i i i l l l n n n o o o o o o o o r r s s
s t t u u u u u u y y z z z");
$single = array();
for ($i=0; $i<count($singl e_fr); $i++) {
$single[$single_fr[$i]] = $single_to[$i];
}
// Ligatures
$ligatures = array("Æ"=>"Ae" , "æ"=>"ae", "O"=>"Oe", "o"=>"oe",
"ß"=>"ss");
// German umlauts
$umlauts = array("Ä"=>"Ae" , "ä"=>"ae", "Ö"=>"Oe", "ö"=>"oe", "Ü"=>"Ue",
"ü"=>"ue");
// Replace
$replacements= array_merge($si ngle, $ligatures);
if ($german) $replacements= array_merge($re placements, $umlauts);
$string = strtr($string, $replacements);
return $string;
}
function make_url_string ($string) {
$string = strtolower(remo ve_accents($str ing, true));
$string = preg_replace("/([\W]+)/", "-", $string);
return urlencode(trim( $string, "-"));
}
I have 2 questions on this:
1. preg_replace("/([\W]+)/", "-", $string); removes all non-ASCII
characters. Is there any possibility to remove only punctuation and such
stuff, but keep all kinds of letters from whatever character sets?
2. Is there a better way to encode strings for URLs? Or is it maybe
inevitable to collect the real name and the name for the url separately to
get an ASCII-only entry?
Thanks for suggestions!
--
Markus 1 2345
Markus Ernst wrote: 2. Is there a better way to encode strings for URLs?
Arguably. Another way is to take your character, encode it as
UTF-8 octets, and percent-encode that encoding. This is the mapping
of IRIs to URIs described in RFC3987. Take <é> (U+00E9). Encoded as
UTF-8 then percent-encoded, you get %C3%A9 (not %E9). http://host.invalid/caf%C3%A9
--
Jock This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: David C. Taylor |
last post by:
I saw an article that described how to convert the query string into
an Url without a query string and return the page.
For example, this request:
http://www.mywebsite.com/products.aspx?category=motherboard
becomes something like this:
http://www.mywebsite.com/motherboard.aspx
|
by: MARTIN LANNY |
last post by:
Hi All,
In my program I am loading the content of a text file (main.txt) into a
string called 'message'.
What I need is to convert all urls and emails in this string into html.
This is what I did to convert hard returns to <br>'s and it works fine:
Dim sws As New IO.StreamWriter(pathtosave)
|
by: Michal Táborský |
last post by:
I am wondering, if it's effective to use text arrays to store
multilanguage information.
We used to do it like this:
CREATE TABLE product (
id serial NOT NULL,
price float4,
...
)
|
by: Nicole |
last post by:
Hello,
Can anyone tell me or give me an online tool which can help me to
convert php dynamic urls to html urls to make a google friendly
site.I dont have apache server on my computer and I dont want to use
it.Wihtout apache server is it possible? And I amusing windows server
and not Linux.
Thanks
Sunita Bihani
|
by: GM |
last post by:
Dear all,
Could you all give me some guide on how to convert my big5 string to
unicode using python? I already knew that I might use cjkcodecs or
python 2.4 but I still don't have idea on what exactly I should do.
Please give me some sample code if you could. Thanks a lot
Regards,
Gary
| |
by: AG |
last post by:
I have seen the samples for multilanguage support regarding what is normally
static content.
Can anyone point me to a good sample for multilanguage support for dynamic
content. Like a gridview that is populated from a database?
TIA
--
AG
Email: discuss at adhdata dot com
|
by: paolob |
last post by:
I need to provide multilanguage support to my application. I alredy
writed a multilanguage test application, using VS6 and resource only
dll. Now i'm using Visual Studio 2005, I find out that it supports
multilanguage through .resx file, but I can't find a good example that
explains me how to do this.
I appreciate very much if you can point me to good documentation or
examples, or if you can give me some tips.
Regards
Paolo
|
by: SM |
last post by:
Hi,
I have a column with SQL Server type binary(20) (contain a sql handle, ex :
0x01000800B73B573B98C6B1030000000000000000)
I want to convert this column to string value with this code :
string sql_hndl = MyDataRow.tostring;
I'm expecting '0x01000800B73B573B98C6B1030000000000000000' string value, but
|
by: Larry Neylon |
last post by:
Hi there,
We are in the process of implementing Membership and Role Management and
have a problem with the connection strings in our web.config.
We currently have a system that on Application_Start set the
Application to the relevant ConnectionString from the
web.config based upon the domain (so we can handle dev/test/live, etc).
The problem we have is that we can't see how to dynamically set the
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |