Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F93153842
urisprintf.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Tue, Nov 26, 15:09
Size
1 KB
Mime Type
text/x-php
Expires
Thu, Nov 28, 15:09 (2 d)
Engine
blob
Format
Raw Data
Handle
22585071
Attached To
rPHU libphutil
urisprintf.php
View Options
<?php
/**
* Format a URI. This function behaves like sprintf(), except that all the
* normal conversions (like %s) will be properly escaped, and additional
* conversions are supported:
*
* %s (String)
* Escapes text for use in a URI.
*
* %p (Path Component)
* Escapes text for use in a URI path component.
*
* %R (Raw String)
* Inserts raw, unescaped text. DANGEROUS!
*/
function
urisprintf
(
$pattern
/* , ... */
)
{
$args
=
func_get_args
();
return
xsprintf
(
'xsprintf_uri'
,
null
,
$args
);
}
function
vurisprintf
(
$pattern
,
array
$argv
)
{
array_unshift
(
$argv
,
$pattern
);
return
call_user_func_array
(
'urisprintf'
,
$argv
);
}
/**
* uri_sprintf() callback for URI encoding.
* @group markup
*/
function
xsprintf_uri
(
$userdata
,
&
$pattern
,
&
$pos
,
&
$value
,
&
$length
)
{
$type
=
$pattern
[
$pos
];
switch
(
$type
)
{
case
's'
:
$value
=
phutil_escape_uri
(
$value
);
$type
=
's'
;
break
;
case
'p'
:
$value
=
phutil_escape_uri_path_component
(
$value
);
$type
=
's'
;
break
;
case
'R'
:
$type
=
's'
;
break
;
}
$pattern
[
$pos
]
=
$type
;
}
Event Timeline
Log In to Comment