Skip to content

Commit

Permalink
all areas MDL-20821 Replaced instances of ereg_replace and eregi_repl…
Browse files Browse the repository at this point in the history
…ace with preg_replace
  • Loading branch information
Andrew Davis committed Nov 17, 2009
1 parent 2ec6307 commit c78a948
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 43 deletions.
2 changes: 1 addition & 1 deletion auth/shibboleth/logout.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ function LogoutNotification($SessionID){
while (($file = readdir($dh)) !== false) {
// Check if it is a file
if (is_file($dir.'/'.$file)){
$session_key = ereg_replace('sess_', '', $file);
$session_key = preg_replace('/sess_/', '', $file);

// Read session file data
$data = file($dir.'/'.$file);
Expand Down
2 changes: 1 addition & 1 deletion filter/tex/filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ function filter ($text) {
$texexp = str_replace('</nolink>','',$texexp);
$texexp = str_replace('<span class="nolink">','',$texexp);
$texexp = str_replace('</span>','',$texexp);
$texexp = eregi_replace("<br[[:space:]]*\/?>", '', $texexp); //dlnsk
$texexp = preg_replace("/<br[[:space:]]*\/?>/i", '', $texexp); //dlnsk
$align = "middle";
if (preg_match('/^align=bottom /',$texexp)) {
$align = "text-bottom";
Expand Down
2 changes: 1 addition & 1 deletion lib/htmlpurifier/HTMLPurifier/AttrDef/Lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class HTMLPurifier_AttrDef_Lang extends HTMLPurifier_AttrDef
public function validate($string, $config, $context) {

// moodle change - we use special lang strings unfortunatelly
return ereg_replace('[^0-9a-zA-Z_-]', '', $string);
return preg_replace('/[^0-9a-zA-Z_-]/', '', $string);
// moodle change end

$string = trim($string);
Expand Down
2 changes: 1 addition & 1 deletion lib/packer/file_archive.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ protected function mangle_pathname($localname) {
}
}

$result = ereg_replace('\.\.+', '', $result);
$result = preg_replace('/\.\.+/', '', $result);
$result = ltrim($result); // no leadin /

if ($result === '.') {
Expand Down
4 changes: 2 additions & 2 deletions lib/typo3/class.t3lib_cs.php
Original file line number Diff line number Diff line change
Expand Up @@ -794,8 +794,8 @@ function entities_to_utf8($str,$alsoStdHtmlEnt=0) {
$trans_tbl = array_flip(get_html_translation_table(HTML_ENTITIES)); // Getting them in iso-8859-1 - but thats ok since this is observed below.
}

$token = md5(microtime());
$parts = explode($token,ereg_replace('(&([#[:alnum:]]*);)',$token.'\2'.$token,$str));
$token = 'a'.md5(microtime());//token must start with a letter or preg_replace substitution won't work
$parts = explode($token,preg_replace('/(&([#[:alnum:]]*);)/',$token.'\2'.$token,$str));
foreach($parts as $k => $v) {
if ($k%2) {
if (substr($v,0,1)=='#') { // Dec or hex entities:
Expand Down
24 changes: 12 additions & 12 deletions lib/typo3/class.t3lib_div.php
Original file line number Diff line number Diff line change
Expand Up @@ -1147,7 +1147,7 @@ public static function modifyHTMLColorAll($color,$all) {
* @return string
*/
public static function rm_endcomma($string) {
return ereg_replace(',$','',$string);
return preg_replace('/,$/','',$string);
}

/**
Expand Down Expand Up @@ -1287,7 +1287,7 @@ public static function splitCalc($string,$operators) {
* @see calcParenthesis()
*/
public static function calcPriority($string) {
$string=ereg_replace('[[:space:]]*','',$string); // removing all whitespace
$string=preg_replace('/[ ]*/','',$string); // removing all whitespace
$string='+'.$string; // Ensuring an operator for the first entrance
$qm='\*\/\+-^%';
$regex = '(['.$qm.'])(['.$qm.']?[0-9\.]*)';
Expand Down Expand Up @@ -1370,7 +1370,7 @@ public static function htmlspecialchars_decode($value) {
* @return string Converted result.
*/
public static function deHSCentities($str) {
return ereg_replace('&amp;([#[:alnum:]]*;)','&\1',$str);
return preg_replace('/&amp;([#A-Za-z0-9]*;)/','&\1',$str);
}

/**
Expand Down Expand Up @@ -1894,7 +1894,7 @@ public static function get_tag_attributes($tag) {
$name = '';
}
} else {
if ($key = strtolower(ereg_replace('[^a-zA-Z0-9]','',$val))) {
if ($key = strtolower(preg_replace('/[^a-zA-Z0-9]/','',$val))) {
$attributes[$key] = '';
$name = $key;
}
Expand All @@ -1917,9 +1917,9 @@ public static function get_tag_attributes($tag) {
* @internal
*/
public static function split_tag_attributes($tag) {
$tag_tmp = trim(eregi_replace ('^<[^[:space:]]*','',trim($tag)));
$tag_tmp = trim(preg_replace ('/^<[^[:space:]]*/i','',trim($tag)));
// Removes any > in the end of the string
$tag_tmp = trim(eregi_replace ('>$','',$tag_tmp));
$tag_tmp = trim(preg_replace ('/>$/i','',$tag_tmp));

$value = array();
while (strcmp($tag_tmp,'')) { // Compared with empty string instead , 030102
Expand Down Expand Up @@ -2184,7 +2184,7 @@ public static function array2xml(array $array,$NSprefix='',$level=0,$docTag='php
}

// The tag name is cleaned up so only alphanumeric chars (plus - and _) are in there and not longer than 100 chars either.
$tagName = substr(ereg_replace('[^[:alnum:]_-]','',$tagName),0,100);
$tagName = substr(preg_replace('/[^[:alnum:]_-]/','',$tagName),0,100);

// If the value is an array then we will call this function recursively:
if (is_array($v)) {
Expand Down Expand Up @@ -2848,7 +2848,7 @@ public static function getFilesInDir($path,$extensionList='',$prependPath=0,$ord
// Initialize variabels:
$filearray = array();
$sortarray = array();
$path = ereg_replace('\/$','',$path);
$path = preg_replace('#\/$#','',$path);

// Find files+directories:
if (@is_dir($path)) {
Expand Down Expand Up @@ -3266,7 +3266,7 @@ public static function linkThisScript(array $getParams=array()) {

$pString = t3lib_div::implodeArrayForUrl('',$params);

return $pString ? $parts.'?'.ereg_replace('^&','',$pString) : $parts;
return $pString ? $parts.'?'.preg_replace('/^&/','',$pString) : $parts;
}

/**
Expand Down Expand Up @@ -3389,7 +3389,7 @@ public static function getIndpEnv($getEnvName) {
list($v,$n) = explode('|',$GLOBALS['TYPO3_CONF_VARS']['SYS']['requestURIvar']);
$retVal = $GLOBALS[$v][$n];
} elseif (!$_SERVER['REQUEST_URI']) { // This is for ISS/CGI which does not have the REQUEST_URI available.
$retVal = '/'.ereg_replace('^/','',t3lib_div::getIndpEnv('SCRIPT_NAME')).
$retVal = '/'.preg_replace('#^/#','',t3lib_div::getIndpEnv('SCRIPT_NAME')).
($_SERVER['QUERY_STRING']?'?'.$_SERVER['QUERY_STRING']:'');
} else {
$retVal = $_SERVER['REQUEST_URI'];
Expand Down Expand Up @@ -3612,11 +3612,11 @@ public static function clientInfo($useragent='') {
break;
case 'msie':
$tmp = strstr($useragent,'MSIE');
$bInfo['VERSION'] = doubleval(ereg_replace('^[^0-9]*','',substr($tmp,4)));
$bInfo['VERSION'] = doubleval(preg_replace('/^[^0-9]*/','',substr($tmp,4)));
break;
case 'opera':
$tmp = strstr($useragent,'Opera');
$bInfo['VERSION'] = doubleval(ereg_replace('^[^0-9]*','',substr($tmp,5)));
$bInfo['VERSION'] = doubleval(preg_replace('/^[^0-9]*/','',substr($tmp,5)));
break;
case 'konqu':
$tmp = strstr($useragent,'Konqueror/');
Expand Down
48 changes: 24 additions & 24 deletions lib/wiki_to_markdown.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,14 @@ function do_replace( $line, $mark, $tag ) {
// BODGE: replace inline $mark characters in places where we want them ignored
// they will be put back after main substitutue, stops problems with eg, and/or
$bodge = chr(1);
$line = eregi_replace( '([[:alnum:]])'.$mark.'([[:alnum:]])', '\\1'.$bodge.'\\2',$line );
$line = preg_replace( '/([[:alnum:]])'.$mark.'([[:alnum:]])/i', '\\1'.$bodge.'\\2',$line );

$regex = '(^| |[(.,])'.$mark.'([^'.$mark.']*)'.$mark.'([^[:alnum:]]|$)';
$regex = '/(^| |[(.,])'.$mark.'([^'.$mark.']*)'.$mark.'([^[:alnum:]]|$)/i';
$replace = '\\1<'.$tag.'>\\2</'.$tag.'>\\3';
$line = eregi_replace( $regex, $replace, $line );
$line = preg_replace( $regex, $replace, $line );

// BODGE: back we go
$line = eregi_replace( $bodge, $mark, $line );
$line = preg_replace( '/'.$bodge.'/i', $mark, $line );

return $line;
}
Expand All @@ -111,14 +111,14 @@ function do_replace_markdown( $line, $mark, $tag ) {
// BODGE: replace inline $mark characters in places where we want them ignored
// they will be put back after main substitutue, stops problems with eg, and/or
$bodge = chr(1);
$line = eregi_replace( '([[:alnum:]])'.$mark.'([[:alnum:]])', '\\1'.$bodge.'\\2',$line );
$line = preg_replace( '/([[:alnum:]])'.$mark.'([[:alnum:]])/i', '\\1'.$bodge.'\\2',$line );

$regex = '(^| |[(.,])'.$mark.'([^'.$mark.']*)'.$mark.'([^[:alnum:]]|$)';
$regex = '/(^| |[(.,])'.$mark.'([^'.$mark.']*)'.$mark.'([^[:alnum:]]|$)/i';
$replace = '\\1'.$tag.'\\2'.$tag.'\\3';
$line = eregi_replace( $regex, $replace, $line );
$line = preg_replace( $regex, $replace, $line );

// BODGE: back we go
$line = eregi_replace( $bodge, $mark, $line );
$line = preg_replace( '/'.$bodge.'/i', $mark, $line );

return $line;
}
Expand All @@ -128,10 +128,10 @@ function do_replace_sub( $line, $mark, $tag ) {
// do regex for subscript and superscript (slightly different)
// $mark is the magic character and $tag the HTML tag to insert

$regex = $mark.'([^'.$mark.']*)'.$mark;
$regex = '/'.$mark.'([^'.$mark.']*)'.$mark.'/i';
$replace = '<'.$tag.'>\\1</'.$tag.'>';

return eregi_replace( $regex, $replace, $line );
return preg_replace( $regex, $replace, $line );
}

function do_list( $line, $blank=false ) {
Expand All @@ -146,7 +146,7 @@ function do_list( $line, $blank=false ) {
else {
$listchar = $line{0};
$count = strspn( $line, $listchar );
$line = eregi_replace( "^[".$listchar."]+ ", "", $line );
$line = preg_replace( "/^[".$listchar."]+ /i", "", $line );
}

// find what sort of list this character represents
Expand Down Expand Up @@ -246,7 +246,7 @@ function line_replace( $line ) {
$line = str_replace( "1/4", "&#188;", $line );
$line = str_replace( "1/2", "&#189;", $line );
$line = str_replace( "3/4", "&#190;", $line );
$line = eregi_replace( "([[:digit:]]+[[:space:]]*)x([[:space:]]*[[:digit:]]+)", "\\1&#215;\\2", $line ); // (digits) x (digits) - multiply
$line = preg_replace( "/([[:digit:]]+[[:space:]]*)x([[:space:]]*[[:digit:]]+)/i", "\\1&#215;\\2", $line ); // (digits) x (digits) - multiply
// do formatting tags
// NOTE: The / replacement *has* to be first, or it will screw the
// HTML tags that are added by the other ones
Expand All @@ -262,48 +262,48 @@ function line_replace( $line ) {

// convert urls into proper link with optional link text URL(text)
// MARDOWN: HTML conversion should work fine
$line = eregi_replace("([[:space:]]|^)([[:alnum:]]+)://([^[:space:]]*)([[:alnum:]#?/&=])\(([^)]+)\)",
$line = preg_replace("/([[:space:]]|^)([[:alnum:]]+)://([^[:space:]]*)([[:alnum:]#?/&=])\(([^)]+)\)/i",
"\\1[\\5](\\2://\\3\\4)", $line);
$line = eregi_replace("([[:space:]])www\.([^[:space:]]*)([[:alnum:]#?/&=])\(([^)]+)\)",
$line = preg_replace("/([[:space:]])www\.([^[:space:]]*)([[:alnum:]#?/&=])\(([^)]+)\)/i",
"\\1[\\5](http://www.\\2\\3)", $line);

// make urls (with and without httpd) into proper links
$line = eregi_replace("([[:space:]]|^)([[:alnum:]]+)://([^[:space:]]*)([[:alnum:]#?/&=])",
$line = preg_replace("/([[:space:]]|^)([[:alnum:]]+)://([^[:space:]]*)([[:alnum:]#?/&=])/i",
"\\1<\\2://\\3\\4>", $line);
$line = eregi_replace("([[:space:]])www\.([^[:space:]]*)([[:alnum:]#?/&=])",
$line = preg_replace("/([[:space:]])www\.([^[:space:]]*)([[:alnum:]#?/&=])/i",
"\\1<http://www.\\2\\3\>", $line);

// make email addresses into mailtos....
// MARKDOWN doesn't quite support this, so do as html
$line = eregi_replace("([[:space:]]|^)([[:alnum:]._-]+@[[:alnum:]._-]+)\(([^)]+)\)",
$line = preg_replace("/([[:space:]]|^)([[:alnum:]._-]+@[[:alnum:]._-]+)\(([^)]+)\)/i",
"\\1<a href=\"mailto:\\2\">\\3</a>", $line);

// !# at the beginning of any lines means a heading
// MARKDOWN: value (1-6) becomes number of hashes
if (eregi( "^!([1-6]) (.*)$", $line, $regs )) {
if (preg_match( "/^!([1-6]) (.*)$/i", $line, $regs )) {
$depth = substr( $line, 1, 1 );
$out = substr( '##########', 0, $depth);
$line = eregi_replace( "^!([1-6]) (.*)$", "$out \\2", $line );
$line = preg_replace( "/^!([1-6]) (.*)$/i", "$out \\2", $line );
}

// acronym handing, example HTML(Hypertext Markyp Language)
// MARKDOWN: no equiv. so just leave as HTML
$line = ereg_replace( "([A-Z]+)\(([^)]+)\)", "<acronym title=\"\\2\">\\1</acronym>", $line );
$line = preg_replace( "/([A-Z]+)\(([^)]+)\)/", "<acronym title=\"\\2\">\\1</acronym>", $line );

// Replace resource link >>##(Description Text)
// MARKDOWN: change to MD web link style
$line = eregi_replace( " ([a-zA-Z]+):([0-9]+)\(([^)]+)\)",
$line = preg_replace("/ ([a-zA-Z]+):([0-9]+)\(([^)]+)\)/i",
" [\\3](".$CFG->wwwroot."/mod/\\1/view.php?id=\\2) ", $line );

require_once($CFG->libdir.'/filelib.php');
$coursefileurl = get_file_url($this->courseid);

// Replace picture resource link
$line = eregi_replace( "/([a-zA-Z0-9./_-]+)(png|gif|jpg)\(([^)]+)\)",
$line = preg_replace("#/([a-zA-Z0-9./_-]+)(png|gif|jpg)\(([^)]+)\)#i",
"![\\3](".$coursefileurl."/\\1\\2)", $line );

// Replace file resource link
$line = eregi_replace( "file:/([[:alnum:]/._-]+)\(([^)]+)\)",
$line = preg_replace("#file:/([[:alnum:]/._-]+)\(([^)]+)\)#i",
"[\\2](".$coursefileurl."/\\1)", $line );

return $line;
Expand Down Expand Up @@ -359,7 +359,7 @@ function convert( $content,$courseid ) {
if (eregi("^\% ",$line) ) {
// preformatted text - no processing
// MARKDOWN: this is MD code form of a paragraph
$buffer = $buffer . " " . eregi_replace( "^\%","",$line) . "\n";
$buffer = $buffer . " " . preg_replace( "/^\%/i","",$line) . "\n";
$this->block_state = STATE_NOTIKI;
}
else {
Expand Down
2 changes: 1 addition & 1 deletion lib/xmldb/xmldb_object.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ function setName($name) {
function checkName () {
$result = true;

if ($this->name != eregi_replace('[^a-z0-9_ -]', '', $this->name)) {
if ($this->name != preg_replace('/[^a-z0-9_ -]/i', '', $this->name)) {
$result = false;
}
return $result;
Expand Down

0 comments on commit c78a948

Please sign in to comment.