Web студия "GrandView"
  Главная   Написать Контакты
   
   
О проекте
Руководство php
 

rawurlencode

(PHP 3, PHP 4, PHP 5)

rawurlencode -- URL-encode according to RFC 1738

Description

string rawurlencode ( string str )

Returns a string in which all non-alphanumeric characters except -_. have been replaced with a percent (%) sign followed by two hex digits. This is the encoding described in RFC 1738 for protecting literal characters from being interpreted as special URL delimiters, and for protecting URLs from being mangled by transmission media with character conversions (like some email systems). For example, if you want to include a password in an FTP URL:

Пример 1. rawurlencode() example 1

<?php
echo '<a href="ftp://user:', rawurlencode('foo @+%/'),
    
'@ftp.example.com/x.txt">';
?>

Or, if you pass information in a PATH_INFO component of the URL:

Пример 2. rawurlencode() example 2

<?php
echo '<a href="http://example.com/department_list_script/',
   
rawurlencode('sales and marketing/Miami'), '">';
?>

See also rawurldecode(), urldecode(), urlencode() and RFC 1738.



urldecode> <rawurldecode
Last updated: Sat, 27 Jan 2007
 
add a note add a note User Contributed Notes
rawurlencode
daggillies at gmail dot com
20-Jul-2007 09:19
When passing variables from JavaScript to PHP (via AJAX, perhaps, or by setting location.href), the analogue of this function is encodeURIComponent()

Example:
<?php // JavaScript actually
var comments=document.getElementById('comments').value;
var
url=location.protocol+'//'+location.host+
  
'/handle_form.php?comments='+encodeURIComponent(comments);
location.href=url;
?>
christian _no interest in at spam dot com
25-Jan-2007 05:53
I had serious trouble with local Windows paths containing umlauts on my Apache 2 / Windows NT machine. Apache could not find any of those files if I just used rawurlencode. It's not noted anywhere here, but you fix this by simply making your path utf8 first:

rawurlencode(utf8_encode($str));
Tomek Perlak [tomekperlak at tlen pl]
13-Nov-2006 03:15
Note in regards to 'rickyale at ig dot com dot br' program:

Wouldn't the whole issue be fixed by using charset=utf-8 in the HTML page?

I'm passing some data between the HTML form and an PHP program - my 'special' characters have to do with the Polish alphabet - and it looks like JavaScript encoding actually... works.

Of course, I could have tested only a limitted number of cases.

Just a thought.
piotr DOT wydrych AT gmail DOT com
29-Mar-2006 02:40
You can encode paths using:

<?php
$encoded
= implode("/", array_map("rawurlencode", explode("/", $path)));
?>
jeroen at virtualhost dot nl
27-Feb-2006 03:55
On the comments of rickyale and djmaze...
Is what you try to achieve is not a combination of utf8 and url encoding, e.g. :

<?
$str = "bl
Новости
11 июля 2007
Сайт запущен
© 2007 info@grandviewstudio.com

Deprecated: Function set_magic_quotes_runtime() is deprecated in /home/sites/grandviewstudiocom/www/65f67d67a94ad980786580ae69e11c07/sape.php on line 324

Deprecated: Function set_magic_quotes_runtime() is deprecated in /home/sites/grandviewstudiocom/www/65f67d67a94ad980786580ae69e11c07/sape.php on line 330
Z058440144362 Z348613067571