Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F12655357
pregsprintf.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
pregsprintf.php
View Options
<?php
/**
* Format a regular expression. Supports the following conversions:
*
* %s String
* Escapes a string using `preg_quote`.
*
* %R Raw
* Inserts a raw regular expression.
*
* @param string sprintf()-style format string.
* @param string Flags to use with the regular expression.
* @param ... Zero or more arguments.
* @return string Formatted string.
*/
function
pregsprintf
(
$pattern
/* , ... */
)
{
$args
=
func_get_args
();
$flags
=
head
(
array_splice
(
$args
,
1
,
1
));
$delim
=
chr
(
7
);
$userdata
=
array
(
'delimiter'
=>
$delim
);
$pattern
=
xsprintf
(
'xsprintf_regex'
,
$userdata
,
$args
);
return
$delim
.
$pattern
.
$delim
.
$flags
;
}
/**
* @{function:xsprintf} callback for regular expressions.
*/
function
xsprintf_regex
(
$userdata
,
&
$pattern
,
&
$pos
,
&
$value
,
&
$length
)
{
$delim
=
idx
(
$userdata
,
'delimiter'
);
$type
=
$pattern
[
$pos
];
switch
(
$type
)
{
case
's'
:
$value
=
preg_quote
(
$value
,
$delim
);
break
;
case
'R'
:
$type
=
's'
;
break
;
}
$pattern
[
$pos
]
=
$type
;
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Fri, Nov 28, 15:03 (1 d, 20 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1046960
Default Alt Text
pregsprintf.php (1 KB)
Attached To
Mode
R118 Arcanist - fork
Attached
Detach File
Event Timeline
Log In to Comment