function coder_upgrade_ereg_to_preg in Coder 7.2
Same name and namespace in other branches
- 7 coder_upgrade/conversions/call.inc \coder_upgrade_ereg_to_preg()
Converts an ereg string to a preg string.
Parameters
string $string:
Return value
string
1 call to coder_upgrade_ereg_to_preg()
- coder_upgrade_upgrade_call_file_scan_directory_alter in coder_upgrade/
conversions/ call.inc - Implements hook_upgrade_call_file_scan_directory_alter().
File
- coder_upgrade/
conversions/ call.inc, line 1570 - Provides conversion routines applied to function calls.
Code
function coder_upgrade_ereg_to_preg($string) {
cdp(__FUNCTION__);
// Check for type == T_CONSTANT_ENCAPSED_STRING
// Check for a '/' in the mask and use a different mask or delimit the '/' with '\/'.
$delimiters = array(
'/',
'@',
'#',
'%',
'~',
'',
);
// TODO Are these all legal?
foreach ($delimiters as $delimiter) {
if (strpos($string, $delimiter) === FALSE) {
break;
}
}
if (!$delimiter) {
clp('ERROR: Could not find a suitable delimiter for the regular expression');
$delimiter = '/';
$string = str_replace('/', '\\/', $string);
}
$quote = $string[0];
return $quote . $delimiter . substr($string, 1, -1) . $delimiter . $quote;
}