]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-19418 Replaced ereg* by preg*
authornicolasconnault <nicolasconnault>
Mon, 22 Jun 2009 01:22:37 +0000 (01:22 +0000)
committernicolasconnault <nicolasconnault>
Mon, 22 Jun 2009 01:22:37 +0000 (01:22 +0000)
36 files changed:
admin/mnet/MethodTable.php
admin/uploaduser.php
auth/shibboleth/auth.php
calendar/lib.php
enrol/authorize/enrol_form.php
install.php
lib/moodlelib.php
lib/simpletest/testweblib.php
lib/weblib.php
login/index.php
login/signup_form.php
mnet/lib.php
mod/chat/chatd.php
mod/feedback/analysis_course.php
mod/feedback/lib.php
mod/lesson/format.php
mod/lesson/reformat.php
mod/scorm/datamodels/aicclib.php
mod/scorm/player.php
mod/wiki/lib.php
pix/smartpix.php
question/format.php
question/format/blackboard_six/format.php
question/format/gift/format.php
question/format/qti_two/format.php
question/format/webct/format.php
question/format/xml/format.php
question/type/calculated/edit_calculated_form.php
question/type/calculated/questiontype.php
question/type/calculatedsimple/edit_calculatedsimple_form.php
question/type/calculatedsimple/questiontype.php
question/type/multianswer/questiontype.php
question/type/numerical/questiontype.php
question/type/random/questiontype.php
search/documents/assignment_document.php
user/editadvanced_form.php

index e9c4e6e344bbc153be5757a2fcebe1599e27a5d5..a881a15c8d78fb401b0abc0a28303c0faa7d6719 100644 (file)
@@ -465,15 +465,15 @@ class MethodTable
                 $word0 = strtolower($word0);
                 $word1 = strtolower($word1);
                 
-                $wordBase0 = ereg_replace('^[&$]+','',$word0);
-                $wordBase1 = ereg_replace('^[&$]+','',$word1);
-                $startBase = strtolower(ereg_replace('^[&$]+','',$start));
+                $wordBase0 = preg_replace('/^[&$]+/','',$word0);
+                $wordBase1 = preg_replace('/^[&$]+/','',$word1);
+                $startBase = strtolower(preg_replace('/^[&$]+/','',$start));
 
                 if ($wordBase0 == $startBase) {
                     $type = str_replace(array('(',')'),'', $word1);
                 } elseif($wordBase1 == $startBase) {
                     $type = str_replace(array('(',')'),'', $word0);
-                } elseif( ereg('(^[&$]+)|(\()([a-z0-9]+)(\)$)', $word0, $regs) ) {
+                } elseif( preg_match('/(^[&$]+)|(\()([a-z0-9]+)(\)$)/', $word0, $regs) ) {
                     $tail = str_ireplace($word0, '', $end);
                     $type = $regs[3];
                 } else {
@@ -535,7 +535,7 @@ class MethodTable
         $comment = str_replace("*/", "", $comment);
         $comment = str_replace("*", "", $comment);
         $comment = str_replace("\n", "\\n", trim($comment));
-        $comment = eregi_replace("[\r\t\n ]+", " ", trim($comment));
+        $comment = preg_replace("/[\r\t\n ]+/i", " ", trim($comment));
         $comment = str_replace("\"", "\\\"", $comment);
         return $comment;
     }
index 5d67b4f0089f90d6f4e3bc756b39fa5158a0ab1f..af7290c120ed38c80b0ed69db2f95cfbdf1f44f2 100755 (executable)
@@ -66,12 +66,12 @@ $returnurl = $CFG->wwwroot.'/'.$CFG->admin.'/uploaduser.php';
 $bulknurl  = $CFG->wwwroot.'/'.$CFG->admin.'/user/user_bulk.php';
 
 // array of all valid fields for validation
-$STD_FIELDS = array('id', 'firstname', 'lastname', 'username', 'email', 
-        'city', 'country', 'lang', 'auth', 'timezone', 'mailformat', 
-        'maildisplay', 'maildigest', 'htmleditor', 'ajax', 'autosubscribe', 
-        'mnethostid', 'institution', 'department', 'idnumber', 'skype', 
-        'msn', 'aim', 'yahoo', 'icq', 'phone1', 'phone2', 'address', 
-        'url', 'description', 'oldusername', 'emailstop', 'deleted',  
+$STD_FIELDS = array('id', 'firstname', 'lastname', 'username', 'email',
+        'city', 'country', 'lang', 'auth', 'timezone', 'mailformat',
+        'maildisplay', 'maildigest', 'htmleditor', 'ajax', 'autosubscribe',
+        'mnethostid', 'institution', 'department', 'idnumber', 'skype',
+        'msn', 'aim', 'yahoo', 'icq', 'phone1', 'phone2', 'address',
+        'url', 'description', 'oldusername', 'emailstop', 'deleted',
         'password');
 
 $PRF_FIELDS = array();
@@ -262,7 +262,7 @@ if ($formdata = $mform->is_cancelled()) {
         // normalize username
         $user->username = $textlib->strtolower($user->username);
         if (empty($CFG->extendedusernamechars)) {
-            $user->username = eregi_replace('[^(-\.[:alnum:])]', '', $user->username);
+            $user->username = preg_replace('/[^(-\.[:alnum:])]/i', '', $user->username);
         }
         if (empty($user->username)) {
             $upt->track('status', get_string('missingfield', 'error', 'username'), 'error');
@@ -1010,4 +1010,4 @@ function uu_allowed_roles($shortname=false) {
 
     return $choices;
 }
-?>
\ No newline at end of file
+?>
index faa0fc4ee2b49fdb070c0b702818599aa55bd511..f69bee1e976e6bc0c5f8b56691b278e0ded6ed66 100644 (file)
@@ -63,7 +63,7 @@ class auth_plugin_shibboleth extends auth_plugin_base {
             } else {
                 // Try to find out using the user's cookie
                 foreach ($_COOKIE as $name => $value){
-                    if (eregi('_shibsession_', $name)){
+                    if (preg_match('/_shibsession_/i', $name)){
                         $sessionkey = $value;
                     }
                 }
index 37d890fd4b9ec330711d7465a5483dcc3fbd6c81..f4a9a4986af40fd7714acb3ae78bce45c8646334 100644 (file)
@@ -770,8 +770,8 @@ function calendar_top_controls($type, $data) {
             $text = get_string('strftimedaydate');
             /*
             // Regexp hackery to make a link out of the month/year part
-            $text = ereg_replace('(%B.+%Y|%Y.+%B|%Y.+%m[^ ]+)', '<a href="'.calendar_get_link_href('view.php?view=month&amp;', 1, $data['m'], $data['y']).'">\\1</a>', $text);
-            $text = ereg_replace('(F.+Y|Y.+F|Y.+m[^ ]+)', '<a href="'.calendar_get_link_href('view.php?view=month&amp;', 1, $data['m'], $data['y']).'">\\1</a>', $text);
+            $text = preg_replace('/(%B.+%Y|%Y.+%B|%Y.+%m[^ ]+)/', '<a href="'.calendar_get_link_href('view.php?view=month&amp;', 1, $data['m'], $data['y']).'">\\1</a>', $text);
+            $text = preg_replace('/(F.+Y|Y.+F|Y.+m[^ ]+)/', '<a href="'.calendar_get_link_href('view.php?view=month&amp;', 1, $data['m'], $data['y']).'">\\1</a>', $text);
             */
             // Replace with actual values and lose any day leading zero
             $text = userdate($time, $text);
index bf5c0fc4da2783385b582675cce7ccf897da6de0..56abdda74f7fb701286b30c4f3cf5528b62d93ee 100755 (executable)
@@ -242,7 +242,7 @@ class enrol_authorize_form extends moodleform
 
     private function validate_aba($aba)
     {
-        if (ereg("^[0-9]{9}$", $aba)) {
+        if (preg_match("/^[0-9]{9}$/", $aba)) {
             $n = 0;
             for($i = 0; $i < 9; $i += 3) {
                 $n += (substr($aba, $i, 1) * 3) + (substr($aba, $i + 1, 1) * 7) + (substr($aba, $i + 2, 1));
@@ -272,45 +272,45 @@ class enrol_authorize_form extends moodleform
         $GoodCard = true;
 
         //  Get rid of any non-digits
-        $Num = ereg_replace("[^0-9]", "", $Num);
+        $Num = preg_replace("/[^0-9]~", "", $Num);
 
         // Perform card-specific checks, if applicable
         switch ($Name)
         {
             case "mcd" :
-                $GoodCard = ereg("^5[1-5].{14}$", $Num);
+                $GoodCard = preg_match("/^5[1-5].{14}$/", $Num);
                 break;
 
             case "vis" :
-                $GoodCard = ereg("^4.{15}$|^4.{12}$", $Num);
+                $GoodCard = preg_match("/^4.{15}$|^4.{12}$/", $Num);
                 break;
 
             case "amx" :
-                $GoodCard = ereg("^3[47].{13}$", $Num);
+                $GoodCard = preg_match("/^3[47].{13}$/", $Num);
                 break;
 
             case "dsc" :
-                $GoodCard = ereg("^6011.{12}$", $Num);
+                $GoodCard = preg_match("/^6011.{12}$/", $Num);
                 break;
 
             case "dnc" :
-                $GoodCard = ereg("^30[0-5].{11}$|^3[68].{12}$", $Num);
+                $GoodCard = preg_match("/^30[0-5].{11}$|^3[68].{12}$/", $Num);
                 break;
 
             case "jcb" :
-                $GoodCard = ereg("^3.{15}$|^2131|1800.{11}$", $Num);
+                $GoodCard = preg_match("/^3.{15}$|^2131|1800.{11}$/", $Num);
                 break;
 
             case "dlt" :
-                $GoodCard = ereg("^4.{15}$", $Num);
+                $GoodCard = preg_match("/^4.{15}$/", $Num);
                 break;
 
             case "swi" :
-                $GoodCard = ereg("^[456].{15}$|^[456].{17,18}$", $Num);
+                $GoodCard = preg_match("/^[456].{15}$|^[456].{17,18}$/", $Num);
                 break;
 
             case "enr" :
-                $GoodCard = ereg("^2014.{11}$|^2149.{11}$", $Num);
+                $GoodCard = preg_match("/^2014.{11}$|^2149.{11}$/", $Num);
                 break;
         }
 
index 1f0b23006604b99cfe0ed86a580e79434eff3d7a..0260b6f1309422cc69d9d20b57e4df3ced32eef1 100644 (file)
  */
 
 if (isset($_REQUEST['lang'])) {
-    $lang = eregi_replace('[^A-Za-z0-9_-]', '', $_REQUEST['lang']);
+    $lang = preg_replace('/[^A-Za-z0-9_-]/i', '', $_REQUEST['lang']);
 } else {
     $lang = 'en_utf8';
 }
 
 if (isset($_REQUEST['admin'])) {
-    $admin = eregi_replace('[^A-Za-z0-9_-]', '', $_REQUEST['admin']);
+    $admin = preg_replace('/[^A-Za-z0-9_-]/i', '', $_REQUEST['admin']);
 } else {
     $admin = 'admin';
 }
index 9655b17ba825a91cd0a160b169fe04a8a97513d2..5f2048016fe954704a19322f3c4483b55c6b7253 100644 (file)
@@ -448,19 +448,19 @@ function clean_param($param, $type) {
             return (float)$param;  // Convert to float
 
         case PARAM_ALPHA:        // Remove everything not a-z
-            return eregi_replace('[^a-zA-Z]', '', $param);
+            return preg_replace('/[^a-zA-Z]/i', '', $param);
 
         case PARAM_ALPHAEXT:     // Remove everything not a-zA-Z_- (originally allowed "/" too)
-            return eregi_replace('[^a-zA-Z_-]', '', $param);
+            return preg_replace('/[^a-zA-Z_-]/i', '', $param);
 
         case PARAM_ALPHANUM:     // Remove everything not a-zA-Z0-9
-            return eregi_replace('[^A-Za-z0-9]', '', $param);
+            return preg_replace('/[^A-Za-z0-9]/i', '', $param);
 
         case PARAM_ALPHANUMEXT:     // Remove everything not a-zA-Z0-9_-
-            return eregi_replace('[^A-Za-z0-9_-]', '', $param);
+            return preg_replace('/[^A-Za-z0-9_-]/i', '', $param);
 
         case PARAM_SEQUENCE:     // Remove everything not 0-9,
-            return eregi_replace('[^0-9,]', '', $param);
+            return preg_replace('/[^0-9,]/i', '', $param);
 
         case PARAM_BOOL:         // Convert to 1 or 0
             $tempstr = strtolower($param);
@@ -480,14 +480,14 @@ function clean_param($param, $type) {
             return clean_param(strip_tags($param, '<lang><span>'), PARAM_CLEAN);
 
         case PARAM_SAFEDIR:      // Remove everything not a-zA-Z0-9_-
-            return eregi_replace('[^a-zA-Z0-9_-]', '', $param);
+            return preg_replace('/[^a-zA-Z0-9_-]/i', '', $param);
 
         case PARAM_SAFEPATH:     // Remove everything not a-zA-Z0-9/_-
-            return eregi_replace('[^a-zA-Z0-9/_-]', '', $param);
+            return preg_replace('/[^a-zA-Z0-9\/_-]/i', '', $param); 
 
         case PARAM_FILE:         // Strip all suspicious characters from filename
-            $param = ereg_replace('[[:cntrl:]]|[&<>"`\|\':\\/]', '', $param);
-            $param = ereg_replace('\.\.+', '', $param);
+            $param = preg_replace('~[[:cntrl:]]|[&<>"`\|\':\\/]~', '', $param);
+            $param = preg_replace('~\.\.+~', '', $param);
             if ($param === '.') {
                 $param = '';
             }
@@ -495,10 +495,10 @@ function clean_param($param, $type) {
 
         case PARAM_PATH:         // Strip all suspicious characters from file path
             $param = str_replace('\\', '/', $param);
-            $param = ereg_replace('[[:cntrl:]]|[&<>"`\|\':]', '', $param);
-            $param = ereg_replace('\.\.+', '', $param);
-            $param = ereg_replace('//+', '/', $param);
-            return ereg_replace('/(\./)+', '/', $param);
+            $param = preg_replace('~[[:cntrl:]]|[&<>"`\|\':]~', '', $param);
+            $param = preg_replace('~\.\.+~', '', $param);
+            $param = preg_replace('~//+~', '/', $param);
+            return preg_replace('~/(\./)+~', '/', $param);
 
         case PARAM_HOST:         // allow FQDN or IPv4 dotted quad
             $param = preg_replace('/[^\.\d\w-]/','', $param ); // only allowed chars
@@ -604,7 +604,7 @@ function clean_param($param, $type) {
             //problem, so remove *all* backslash.
             //$param = str_replace('\\', '', $param);
             //remove some nasties
-            $param = ereg_replace('[[:cntrl:]]|[<>`]', '', $param);
+            $param = preg_replace('~[[:cntrl:]]|[<>`]~', '', $param);
             //convert many whitespace chars into one
             $param = preg_replace('/\s+/', ' ', $param);
             $textlib = textlib_get_instance();
@@ -4540,7 +4540,7 @@ function email_to_user($user, $from, $subject, $messagetext, $messagehtml='', $a
     }
 
     if ($attachment && $attachname) {
-        if (ereg( "\\.\\." ,$attachment )) {    // Security check for ".." in dir path
+        if (preg_match( "~\\.\\.~" ,$attachment )) {    // Security check for ".." in dir path
             $mail->AddAddress($supportuser->email, fullname($supportuser, true) );
             $mail->AddStringAttachment('Error in attachment.  User attempted to attach a filename with a unsafe name.', 'error.txt', '8bit', 'text/plain');
         } else {
@@ -5058,7 +5058,7 @@ function make_mod_upload_directory($courseid) {
 function make_user_directory($userid, $test=false) {
     global $CFG;
 
-    if (is_bool($userid) || $userid < 0 || !ereg('^[0-9]{1,10}$', $userid) || $userid > 2147483647) {
+    if (is_bool($userid) || $userid < 0 || !preg_match('/^[0-9]{1,10}$/', $userid) || $userid > 2147483647) {
         if (!$test) {
             notify("Given userid was not a valid integer! (" . gettype($userid) . " $userid)");
         }
@@ -7550,7 +7550,7 @@ function count_letters($string) {
     $textlib = textlib_get_instance();
 
     $string = strip_tags($string); // Tags are out now
-    $string = ereg_replace('[[:space:]]*','',$string); //Whitespace are out now
+    $string = preg_replace('/[[:space:]]*/','',$string); //Whitespace are out now
 
     return $textlib->strlen($string);
 }
@@ -9172,4 +9172,4 @@ function check_consecutive_identical_characters($password, $maxchars) {
     return true;
 }
 
-?>
\ No newline at end of file
+?>
index c98d65769b7b023a2d339d8f3ae6261e2b12eec1..0b08a44336a7d52fc13523fbbca21460bf9e6f4d 100644 (file)
@@ -39,6 +39,7 @@ class web_test extends UnitTestCase {
 
     function test_s() {
           $this->assertEqual(s("This Breaks \" Strict"), "This Breaks &quot; Strict");
+          $this->assertEqual(s("This Breaks <a>\" Strict</a>"), "This Breaks &lt;a&gt;&quot; Strict&lt;/a&gt;");
     }
 
     function test_format_text_email() {
@@ -66,5 +67,10 @@ class web_test extends UnitTestCase {
         $this->assertEqual(highlight('+good', 'This is goodness'), 'This is goodness');
         $this->assertEqual(highlight('good', 'This is goodness'), 'This is <span class="highlight">good</span>ness');
     }
+
+    function test_replace_ampersands() { 
+        $this->assertEqual(replace_ampersands_not_followed_by_entity("This & that &nbsp;"), "This &amp; that &nbsp;");
+        $this->assertEqual(replace_ampersands_not_followed_by_entity("This &nbsp that &nbsp;"), "This &amp;nbsp that &nbsp;");
+    }
 }
 ?>
index 43671abff25ee3ff10da4031f34e1a68d95d71d4..8ccfed3a73d8614748ff6d3d3d8d49324f45e1a8 100644 (file)
@@ -1639,7 +1639,8 @@ function format_string($string, $striplinks=true, $courseid=NULL ) {
     }
 
     // First replace all ampersands not followed by html entity code
-    $string = preg_replace("/\&(?![a-zA-Z0-9#]{1,8};)/", "&amp;", $string);
+    // Regular expression moved to its own method for easier unit testing
+    $string = replace_ampersands_not_followed_by_entity($string);
 
     if (!empty($CFG->filterall) && $CFG->version >= 2009040600) { // Avoid errors during the upgrade to the new system.
         $context = $PAGE->context;
@@ -1664,6 +1665,18 @@ function format_string($string, $striplinks=true, $courseid=NULL ) {
     return $string;
 }
 
+/**
+ * Given a string, performs a negative lookahead looking for any ampersand character
+ * that is not followed by a proper HTML entity. If any is found, it is replaced
+ * by &amp;. The string is then returned.
+ *
+ * @param string $string
+ * @return string
+ */
+function replace_ampersands_not_followed_by_entity($string) {
+    return preg_replace("/\&(?![a-zA-Z0-9#]{1,8};)/", "&amp;", $string);
+}
+
 /**
  * Given text in a variety of format codings, this function returns
  * the text as plain text suitable for plain email.
@@ -1690,7 +1703,7 @@ function format_text_email($text, $format) {
             $text = wiki_to_html($text);
         /// This expression turns links into something nice in a text format. (Russell Jungwirth)
         /// From: http://php.net/manual/en/function.eregi-replace.php and simplified
-            $text = eregi_replace('(<a [^<]*href=["|\']?([^ "\']*)["|\']?[^>]*>([^<]*)</a>)','\\3 [ \\2 ]', $text);
+            $text = preg_replace('~(<a [^<]*href=["|\']?([^ "\']*)["|\']?[^>]*>([^<]*)</a>)~i','$3 [ $2 ]', $text);
             return strtr(strip_tags($text), array_flip(get_html_translation_table(HTML_ENTITIES)));
             break;
 
@@ -1701,7 +1714,7 @@ function format_text_email($text, $format) {
         case FORMAT_MOODLE:
         case FORMAT_MARKDOWN:
         default:
-            $text = eregi_replace('(<a [^<]*href=["|\']?([^ "\']*)["|\']?[^>]*>([^<]*)</a>)','\\3 [ \\2 ]', $text);
+            $text = preg_replace('~(<a [^<]*href=["|\']?([^ "\']*)["|\']?[^>]*>([^<]*)</a>)~i','$3 [ $2 ]', $text);
             return strtr(strip_tags($text), array_flip(get_html_translation_table(HTML_ENTITIES)));
             break;
     }
@@ -1861,8 +1874,8 @@ function clean_text($text, $format=FORMAT_MOODLE) {
             }
 
         /// Remove potential script events - some extra protection for undiscovered bugs in our code
-            $text = eregi_replace("([^a-z])language([[:space:]]*)=", "\\1Xlanguage=", $text);
-            $text = eregi_replace("([^a-z])on([a-z]+)([[:space:]]*)=", "\\1Xon\\2=", $text);
+            $text = preg_replace("~([^a-z])language([[:space:]]*)=~i", "$1Xlanguage=", $text);
+            $text = preg_replace("~([^a-z])on([a-z]+)([[:space:]]*)=~i", "$1Xon$2=", $text);
 
             return $text;
     }
@@ -2105,11 +2118,11 @@ function text_to_html($text, $smiley=true, $para=true, $newlines=true) {
     global $CFG;
 
 /// Remove any whitespace that may be between HTML tags
-    $text = eregi_replace(">([[:space:]]+)<", "><", $text);
+    $text = preg_replace("~>([[:space:]]+)<~i", "><", $text);
 
 /// Remove any returns that precede or follow HTML tags
-    $text = eregi_replace("([\n\r])<", " <", $text);
-    $text = eregi_replace(">([\n\r])", "> ", $text);
+    $text = preg_replace("~([\n\r])<~i", " <", $text);
+    $text = preg_replace("~>([\n\r])~i", "> ", $text);
 
     convert_urls_into_links($text);
 
@@ -2172,11 +2185,11 @@ function html_to_text($html) {
  */
 function convert_urls_into_links(&$text) {
 /// Make lone URLs into links.   eg http://moodle.com/
-    $text = eregi_replace("([[:space:]]|^|\(|\[)([[:alnum:]]+)://([^[:space:]]*)([[:alnum:]#?/&=])",
+    $text = preg_replace("~([[:space:]]|^|\(|\[)([[:alnum:]]+)://([^[:space:]]*)([[:alnum:]#?/&=])~i",
                           "\\1<a href=\"\\2://\\3\\4\" target=\"_blank\">\\2://\\3\\4</a>", $text);
 
 /// eg www.moodle.com
-    $text = eregi_replace("([[:space:]]|^|\(|\[)www\.([^[:space:]]*)([[:alnum:]#?/&=])",
+    $text = preg_replace("~([[:space:]]|^|\(|\[)www\.([^[:space:]]*)([[:alnum:]#?/&=])~i",
                           "\\1<a href=\"http://www.\\2\\3\" target=\"_blank\">www.\\2\\3</a>", $text);
 }
 
index 0184a375dde98ea71eca7c1ad09097ac7a737b0b..82e39766b4a53a7cdb6d7a0305dc34a2fd402ecf 100644 (file)
@@ -95,7 +95,7 @@
         $frm->username = trim(moodle_strtolower($frm->username));
 
         if (is_enabled_auth('none') && empty($CFG->extendedusernamechars)) {
-            $string = eregi_replace("[^(-\.[:alnum:])]", "", $frm->username);
+            $string = preg_replace("~[^(-\.[:alnum:])]~i", "", $frm->username);
             if (strcmp($frm->username, $string)) {
                 $errormsg = get_string('username').': '.get_string("alphanumerical");
                 $errorcode = 2;
index 200fcdb920d93decb6b3ecfa614cb91ff9bbc039..40c79d06bf72a7f819202468e67a9dc9744b8168 100644 (file)
@@ -65,7 +65,7 @@ class login_signup_form extends moodleform {
 
         if (signup_captcha_enabled()) {
             $mform->addElement('recaptcha', 'recaptcha_element', get_string('recaptcha', 'auth'), array('https' => $CFG->loginhttps));
-            $mform->setHelpButton('recaptcha_element', array('recaptcha', get_string('recaptcha', 'auth'))); 
+            $mform->setHelpButton('recaptcha_element', array('recaptcha', get_string('recaptcha', 'auth')));
         }
 
         profile_signup_fields($mform);
@@ -99,7 +99,7 @@ class login_signup_form extends moodleform {
             $errors['username'] = get_string('usernameexists');
         } else {
             if (empty($CFG->extendedusernamechars)) {
-                $string = eregi_replace("[^(-\.[:alnum:])]", '', $data['username']);
+                $string = preg_replace("~[^(-\.[:alnum:])]~i", '', $data['username']);
                 if (strcmp($data['username'], $string)) {
                     $errors['username'] = get_string('alphanumerical');
                 }
index 59050ee6dccad0c76abb90e9022f1f0cc6daf9a9..276ace1c21c3e411c77ee39c3795fe8bdffa2631 100644 (file)
@@ -346,7 +346,7 @@ function mnet_generate_keypair($dn = null, $days=28) {
     }
 
     $host = strtolower($CFG->wwwroot);
-    $host = ereg_replace("^http(s)?://",'',$host);
+    $host = preg_replace("~^http(s)?://~",'',$host);
     $break = strpos($host.'/' , '/');
     $host   = substr($host, 0, $break);
 
index cd99081af651d926dbede5158582bb397e9ffde5..a721e68181462ea8939b22661d911c07786b535e 100755 (executable)
@@ -995,7 +995,7 @@ while(true) {
                     continue;
                 }
 
-                if(!ereg('win=(chat|users|message|beep).*&chat_sid=([a-zA-Z0-9]*) HTTP', $data, $info)) {
+                if(!preg_match('/win=(chat|users|message|beep).*&chat_sid=([a-zA-Z0-9]*) HTTP/', $data, $info)) {
                     // Malformed data
                     $DAEMON->trace('UFO with '.$handle.': Request with malformed data; connection closed', E_USER_WARNING);
                     $DAEMON->dismiss_ufo($handle, true, 'Request with malformed data; connection closed');
@@ -1021,7 +1021,7 @@ while(true) {
                     break;
                     case 'beep':
                         $type = CHAT_SIDEKICK_BEEP;
-                        if(!ereg('beep=([^&]*)[& ]', $data, $info)) {
+                        if(!preg_match('/beep=([^&]*)[& ]/', $data, $info)) {
                             $DAEMON->trace('Beep sidekick did not contain a valid userid', E_USER_WARNING);
                             $DAEMON->dismiss_ufo($handle, true, 'Request with malformed data; connection closed');
                             continue;
@@ -1032,7 +1032,7 @@ while(true) {
                     break;
                     case 'message':
                         $type = CHAT_SIDEKICK_MESSAGE;
-                        if(!ereg('chat_message=([^&]*)[& ]chat_msgidnr=([^&]*)[& ]', $data, $info)) {
+                        if(!preg_match('/chat_message=([^&]*)[& ]chat_msgidnr=([^&]*)[& ]/', $data, $info)) {
                             $DAEMON->trace('Message sidekick did not contain a valid message', E_USER_WARNING);
                             $DAEMON->dismiss_ufo($handle, true, 'Request with malformed data; connection closed');
                             continue;
index 9e1aead342af7f8cc6a86430445ef5ad0a7c1157..1d3d90a3ca8d0b4505d9088610a7b804b3e2501c 100644 (file)
                 $printnr = '';
             }
             $itemobj->print_analysed($item, $printnr, $mygroupid, $coursefilter);
-            if (eregi('rated$', $item->typ)) {
+            if (preg_match('/rated$/i', $item->typ)) {
                  echo '<tr><td colspan="2"><a href="#" onclick="setcourseitemfilter('.$item->id.',\''.$item->typ.'\'); return false;">'.
                     get_string('sort_by_course', 'feedback').'</a></td></tr>'; 
             }
index 6777d6ee0943d34a4eb961cb8f139e4b6b88d118..72511e19b86ff99e49cfc185ac989e6a85cd5819 100644 (file)
@@ -1613,7 +1613,7 @@ function feedback_create_values($data, $usrid, $timemodified, $tmp = false, $gue
     $errcount = 0;
     foreach($keys as $key){
         //ensure the keys are what we want
-        if(eregi('([a-z0-9]{1,})_([0-9]{1,})',$key)){
+        if(preg_match('/([a-z0-9]{1,})_([0-9]{1,})/i',$key)){
             $value = new object();
             $itemnr = explode('_', $key);
             $value->item = intval($itemnr[1]);
@@ -1659,7 +1659,7 @@ function feedback_update_values($data, $completed, $tmp = false) {
     $keys = array_keys($data);
     foreach($keys as $key){
         //ensure the keys are what we want
-        if(eregi('([a-z0-9]{1,})_([0-9]{1,})',$key)){
+        if(preg_match('/([a-z0-9]{1,})_([0-9]{1,})/i',$key)){
             //build the new value to update([id], item, completed, value)
             $itemnr = explode('_', $key);
             $newvalue = new object();
index 34f73fe7b25508127298cf4a86c77b666fc389eb..eb8dc7230dcab72e5214f1f37cede3f4d46809be 100644 (file)
@@ -154,7 +154,7 @@ class qformat_default {
             $filearray = file($filename);
 
             /// Check for Macintosh OS line returns (ie file on one line), and fix
-            if (ereg("\r", $filearray[0]) AND !ereg("\n", $filearray[0])) {
+            if (preg_match("/\r/", $filearray[0]) AND !preg_match("/\n/", $filearray[0])) {
                 return explode("\r", $filearray[0]);
             } else {
                 return $filearray;
index e13bc76207858b7270d53f0a5c3dccf364181622..cdf2577022a770eb8fea6ead0c07eb8fe8ecf148 100644 (file)
@@ -13,7 +13,7 @@ function removedoublecr($filename) {
     
     $filearray = file($filename);
     /// Check for Macintosh OS line returns (ie file on one line), and fix
-    if (ereg("\r", $filearray[0]) AND !ereg("\n", $filearray[0])) {
+    if (preg_match("/\r/", $filearray[0]) AND !preg_match("/\n/", $filearray[0])) {
         $outfile = explode("\r", $filearray[0]);
     } else {
         $outfile = $filearray;
index 10759730444d71c6043627e78d923dff61d28cb0..9fdf26a5fd98d0fd3b41fd4e02980731b89617cc 100644 (file)
@@ -302,7 +302,7 @@ function scorm_parse_aicc($scorm) {
                             }
                             if (isset($element->core_vendor)) {
                                 $scodata->name = 'datafromlms';
-                                $scodata->value = eregi_replace('<cr>', "\r\n", $element->core_vendor);
+                                $scodata->value = preg_replace('/<cr>/i', "\r\n", $element->core_vendor);
                                 $dataid = $DB->insert_record('scorm_scoes_data',$scodata);
                             }
                         }
index a24d9499e02d71199126caedbd6528f62f77bc2e..b0a6091dbca829dfcf7d63f5a227833f4d02bbab 100755 (executable)
             echo "                <iframe id=\"scoframe1\" class=\"scoframe\" name=\"scoframe1\" src=\"{$fullurl}\"></iframe>\n";
         } else {
             // Clean the name for the window as IE is fussy
-            $name = ereg_replace("[^A-Za-z0-9]", "", $scorm->name);
+            $name = preg_replace("/[^A-Za-z0-9]/", "", $scorm->name);
             if (!$name) {
                 $name = 'DefaultPlayerWindow';
             }
             </div> <!-- SCORM object -->
         </div> <!-- SCORM box  -->
     </div> <!-- SCORM page -->
-<?php print_footer('none'); ?>
\ No newline at end of file
+<?php print_footer('none'); ?>
index ce2a61776dd141d3c30527162ac36663fc9a683f..950523eef90233ac0cab3cfaebd4e38b6b7fc7a1 100644 (file)
@@ -1920,7 +1920,7 @@ function wiki_admin_checklinks($pagetocheck) {
      }
 
      /// Remove old Notices
-     $content = eregi_replace(' ÂµÂµ__~\['.get_string("offline","wiki").'\]__µµ ','', $content);
+     $content = preg_replace('/ ÂµÂµ__~\['.get_string("offline","wiki").'\]__µµ /i','', $content);
 
      #-- replace dead links
      foreach ($badlinks as $href) {
index e44628de5ac134102eb327744137aa3820f7612f..bb1c72d4b606cb4a0a5def322a61e82a1f5531eb 100644 (file)
@@ -21,10 +21,10 @@ function makesafe($param) {
     $param = str_replace('\\\'', '\'', $param);
     $param = str_replace('\\"', '"', $param);
     $param = str_replace('\\', '/', $param);
-    $param = ereg_replace('[[:cntrl:]]|[<>"`\|\':]', '', $param);
-    $param = ereg_replace('\.\.+', '', $param);
-    $param = ereg_replace('//+', '/', $param);
-    return ereg_replace('/(\./)+', '/', $param);
+    $param = preg_replace('/[[:cntrl:]]|[<>"`\|\':]/', '', $param);
+    $param = preg_replace('/\.\.+/', '', $param);
+    $param = preg_replace('~//+~', '/', $param);
+    return preg_replace('~/(\./)+~', '/', $param);
 }
 
 // Nicked from weblib
index 76d12731d23f86f63114374b4ceeebf787dba7f6..5108c509e2e0f07c4b0b01babf1cadc5a14089e1 100644 (file)
@@ -423,7 +423,7 @@ class qformat_default {
             $filearray = file($filename);
 
             /// Check for Macintosh OS line returns (ie file on one line), and fix
-            if (ereg("\r", $filearray[0]) AND !ereg("\n", $filearray[0])) {
+            if (preg_match("~\r~", $filearray[0]) AND !preg_match("~\n~", $filearray[0])) {
                 return explode("\r", $filearray[0]);
             } else {
                 return $filearray;
@@ -572,7 +572,7 @@ class qformat_default {
         fclose( $fh );
 
         // return the (possibly) new filename
-        $newfile = ereg_replace("{$CFG->dataroot}/{$this->course->id}/", '',$newfullpath);
+        $newfile = preg_replace("~{$CFG->dataroot}/{$this->course->id}/~", '',$newfullpath);
         return $newfile;
     }
 
index 6f8ed255fa16f270249ec923331dfdd5edad49a6..1cf7e36942be9448bc23d928d1d6b38886a4af85 100644 (file)
@@ -180,7 +180,7 @@ class qformat_blackboard_six extends qformat_default {
                         if (is_readable($q_file)) {
                             $filearray = file($q_file);
                             /// Check for Macintosh OS line returns (ie file on one line), and fix
-                            if (ereg("\r", $filearray[0]) AND !ereg("\n", $filearray[0])) {
+                            if (preg_match("~\r~", $filearray[0]) AND !preg_match("~\n~", $filearray[0])) {
                                 return explode("\r", $filearray[0]);
                             } else {
                                 return $filearray;
index 08a3b857fd0f72e56de77eac32f82fcf634aec76..c246dceee4fe5bac346f3c0052d0f628b7673f9b 100755 (executable)
@@ -119,7 +119,7 @@ class qformat_gift extends qformat_default {
         $question = $this->defaultquestion();
         $comment = NULL;
         // define replaced by simple assignment, stop redefine notices
-        $gift_answerweight_regex = "^%\-*([0-9]{1,2})\.?([0-9]*)%";        
+        $gift_answerweight_regex = "/^%\-*([0-9]{1,2})\.?([0-9]*)%/";        
 
         // REMOVED COMMENTED LINES and IMPLODE
         foreach ($lines as $key => $line) {
@@ -139,7 +139,7 @@ class qformat_gift extends qformat_default {
         $text = $this->escapedchar_pre($text);
 
         // Look for category modifier
-        if (ereg( '^\$CATEGORY:', $text)) {
+        if (preg_match( '~^\$CATEGORY:~', $text)) {
             // $newcategory = $matches[1];
             $newcategory = trim(substr( $text, 10 ));
 
@@ -317,7 +317,7 @@ class qformat_gift extends qformat_default {
                         $answer_weight = 1;
                         $answer = substr($answer, 1);
     
-                    } elseif (ereg($gift_answerweight_regex, $answer)) {    // check for properly formatted answer weight
+                    } elseif (preg_match($gift_answerweight_regex, $answer)) {    // check for properly formatted answer weight
                         $answer_weight = $this->answerweightparser($answer);
                     
                     } else {     //default, i.e., wrong anwer
@@ -408,7 +408,7 @@ class qformat_gift extends qformat_default {
                     $answer = trim($answer);
 
                     // Answer Weight
-                    if (ereg($gift_answerweight_regex, $answer)) {    // check for properly formatted answer weight
+                    if (preg_match($gift_answerweight_regex, $answer)) {    // check for properly formatted answer weight
                         $answer_weight = $this->answerweightparser($answer);
                     } else {     //default, i.e., full-credit anwer
                         $answer_weight = 1;
@@ -456,7 +456,7 @@ class qformat_gift extends qformat_default {
                     $answer = trim($answer);
 
                     // Answer weight
-                    if (ereg($gift_answerweight_regex, $answer)) {    // check for properly formatted answer weight
+                    if (preg_match($gift_answerweight_regex, $answer)) {    // check for properly formatted answer weight
                         $answer_weight = $this->answerweightparser($answer);
                     } else {     //default, i.e., full-credit anwer
                         $answer_weight = 1;
index 6542587ac7d5adabb3f883771a8e055078ec6035..e3fc297ba0f95e97aaec873325e202196ad3ec8d 100644 (file)
@@ -33,8 +33,8 @@ class qformat_qti_two extends qformat_default {
         // Remove all tabs.
         $source = str_replace("\t", '', $source);
         // Remove all space after ">" and before "<".
-        $source = ereg_replace(">( )*", ">", $source);
-        $source = ereg_replace("( )*<", "<", $source);
+        $source = preg_replace("/>( )*", ">/", $source);
+        $source = preg_replace("/( )*<", "</", $source);
 
         // Iterate through the source.
         $level = 0;
index f97b488044a980c6a9231d41cc05771d3614e226..9c64a4c1b36ed816c1a5deb8b89aeae1c542bc2e 100644 (file)
@@ -70,21 +70,20 @@ function qformat_webct_convert_formula($formula) {
     $formula = str_replace(' ', '', $formula);
 
     // Remove paranthesis after e,E and *10**:
-    while (ereg('[0-9.](e|E|\\*10\\*\\*)\\([+-]?[0-9]+\\)', $formula, $regs)) {
+    while (preg_match('~[0-9.](e|E|\\*10\\*\\*)\\([+-]?[0-9]+\\)~', $formula, $regs)) {
         $formula = str_replace(
-                $regs[0], ereg_replace('[)(]', '', $regs[0]), $formula);
+                $regs[0], preg_replace('/[)(]/', '', $regs[0]), $formula);
     }
 
     // Replace *10** with e where possible
-    while (ereg(
-            '(^[+-]?|[^eE][+-]|[^0-9eE+-])[0-9.]+\\*10\\*\\*[+-]?[0-9]+([^0-9.eE]|$)',
+    while (preg_match('~(^[+-]?|[^eE][+-]|[^0-9eE+-])[0-9.]+\\*10\\*\\*[+-]?[0-9]+([^0-9.eE]|$)~',
             $formula, $regs)) {
         $formula = str_replace(
                 $regs[0], str_replace('*10**', 'e', $regs[0]), $formula);
     }
 
     // Replace other 10** with 1e where possible
-    while (ereg('(^|[^0-9.eE])10\\*\\*[+-]?[0-9]+([^0-9.eE]|$)', $formula, $regs)) {
+    while (preg_match('~(^|[^0-9.eE])10\\*\\*[+-]?[0-9]+([^0-9.eE]|$)~', $formula, $regs)) {
         $formula = str_replace(
                 $regs[0], str_replace('10**', '1e', $regs[0]), $formula);
     }
@@ -94,17 +93,17 @@ function qformat_webct_convert_formula($formula) {
     while (2 == count($splits = explode('**', $formula, 2))) {
 
         // Find $base
-        if (ereg('^(.*[^0-9.eE])?(([0-9]+(\\.[0-9]*)?|\\.[0-9]+)([eE][+-]?[0-9]+)?|\\{[^}]*\\})$',
+        if (preg_match('~^(.*[^0-9.eE])?(([0-9]+(\\.[0-9]*)?|\\.[0-9]+)([eE][+-]?[0-9]+)?|\\{[^}]*\\})$~',
                 $splits[0], $regs)) {
             // The simple cases
             $base = $regs[2];
             $splits[0] = $regs[1];
 
-        } else if (ereg('\\)$', $splits[0])) {
+        } else if (preg_match('~\\)$~', $splits[0])) {
             // Find the start of this parenthesis
             $deep = 1;
             for ($i = 1 ; $deep ; ++$i) {
-                if (!ereg('^(.*[^[:alnum:]_])?([[:alnum:]_]*([)(])([^)(]*[)(]){'.$i.'})$',
+                if (!preg_match('~^(.*[^[:alnum:]_])?([[:alnum:]_]*([)(])([^)(]*[)(]){'.$i.'})$~',
                         $splits[0], $regs)) {
                     print_error("parenthesisinproperstart", 'question', '', $splits[0]);
                 }
@@ -124,17 +123,17 @@ function qformat_webct_convert_formula($formula) {
         }
 
         // Find $exp (similar to above but a little easier)
-        if (ereg('^([+-]?(\\{[^}]\\}|([0-9]+(\\.[0-9]*)?|\\.[0-9]+)([eE][+-]?[0-9]+)?))(.*)',
+        if (preg_match('~^([+-]?(\\{[^}]\\}|([0-9]+(\\.[0-9]*)?|\\.[0-9]+)([eE][+-]?[0-9]+)?))(.*)~',
                 $splits[1], $regs)) {
             // The simple case
             $exp = $regs[1];
             $splits[1] = $regs[6];
 
-        } else if (ereg('^[+-]?[[:alnum:]_]*\\(', $splits[1])) {
+        } else if (preg_match('~^[+-]?[[:alnum:]_]*\\(~', $splits[1])) {
             // Find the end of the parenthesis
             $deep = 1;
             for ($i = 1 ; $deep ; ++$i) {
-                if (!ereg('^([+-]?[[:alnum:]_]*([)(][^)(]*){'.$i.'}([)(]))(.*)',
+                if (!preg_match('~^([+-]?[[:alnum:]_]*([)(][^)(]*){'.$i.'}([)(]))(.*)~',
                         $splits[1], $regs)) {
                     print_error("parenthesisinproperclose", 'question', '', $splits[1]);
                 }
@@ -190,7 +189,7 @@ class qformat_webct extends qformat_default {
             // Processing multiples lines strings
 
             if (isset($questiontext) and is_string($questiontext)) {
-                if (ereg("^:",$line)) {
+                if (preg_match("~^:~",$line)) {
                     $question->questiontext = trim($questiontext);
                     unset($questiontext);
                 }
@@ -201,7 +200,7 @@ class qformat_webct extends qformat_default {
             }
 
             if (isset($answertext) and is_string($answertext)) {
-                if (ereg("^:",$line)) {
+                if (preg_match("~^:~",$line)) {
                     $answertext = trim($answertext);
                     $question->answer[$currentchoice] = $answertext;
                     $question->subanswers[$currentchoice] = $answertext;
@@ -214,7 +213,7 @@ class qformat_webct extends qformat_default {
             }
 
             if (isset($responsetext) and is_string($responsetext)) {
-                if (ereg("^:",$line)) {
+                if (preg_match("~^:~",$line)) {
                     $question->subquestions[$currentchoice] = trim($responsetext);
                     unset($responsetext);
                 }
@@ -225,7 +224,7 @@ class qformat_webct extends qformat_default {
             }
 
             if (isset($feedbacktext) and is_string($feedbacktext)) {
-                if (ereg("^:",$line)) {
+                if (preg_match("~^:~",$line)) {
                    $question->feedback[$currentchoice] = trim($feedbacktext);
                     unset($feedbacktext);
                 }
@@ -236,7 +235,7 @@ class qformat_webct extends qformat_default {
             }
 
             if (isset($generalfeedbacktext) and is_string($generalfeedbacktext)) {
-                if (ereg("^:",$line)) {
+                if (preg_match("~^:~",$line)) {
                    $question->tempgeneralfeedback= trim($generalfeedbacktext);
                     unset($generalfeedbacktext);
                 }
@@ -248,7 +247,7 @@ class qformat_webct extends qformat_default {
 
             $line = trim($line);
 
-            if (eregi("^:(TYPE|EOF):",$line)) {
+            if (preg_match("~^:(TYPE|EOF):~i",$line)) {
                 // New Question or End of File
                 if (isset($question)) {            // if previous question exists, complete, check and save it
 
@@ -382,7 +381,7 @@ class qformat_webct extends qformat_default {
 
             // Processing Question Header
 
-            if (eregi("^:TYPE:MC:1(.*)",$line,$webct_options)) {
+            if (preg_match("~^:TYPE:MC:1(.*)~i",$line,$webct_options)) {
                 // Multiple Choice Question with only one good answer
                 $question = $this->defaultquestion();
                 $question->feedback = array();
@@ -392,7 +391,7 @@ class qformat_webct extends qformat_default {
                 continue;
             }
 
-            if (eregi("^:TYPE:MC:N(.*)",$line,$webct_options)) {
+            if (preg_match("~^:TYPE:MC:N(.*)~i",$line,$webct_options)) {
                 // Multiple Choice Question with several good answers
                 $question = $this->defaultquestion();
                 $question->feedback = array();
@@ -402,7 +401,7 @@ class qformat_webct extends qformat_default {
                 continue;
             }
 
-            if (eregi("^:TYPE:S",$line)) {
+            if (preg_match("~^:TYPE:S~i",$line)) {
                 // Short Answer Question
                 $question = $this->defaultquestion();
                 $question->feedback = array();
@@ -412,7 +411,7 @@ class qformat_webct extends qformat_default {
                 continue;
             }
 
-            if (eregi("^:TYPE:C",$line)) {
+            if (preg_match("~^:TYPE:C~i",$line)) {
                 // Calculated Question
            /*     $warnings[] = get_string("calculatedquestion", "quiz", $nLineCounter);
                 unset($question);
@@ -434,7 +433,7 @@ class qformat_webct extends qformat_default {
                 continue;
             }
 
-            if (eregi("^:TYPE:M",$line)) {
+            if (preg_match("~^:TYPE:M~i",$line)) {
                 // Match Question
                 $question = $this->defaultquestion();
                 $question->qtype = MATCH;
@@ -443,7 +442,7 @@ class qformat_webct extends qformat_default {
                 continue;
             }
 
-            if (eregi("^:TYPE:P",$line)) {
+            if (preg_match("~^:TYPE:P~i",$line)) {
                 // Paragraph Question
                 $warnings[] = get_string("paragraphquestion", "quiz", $nLineCounter);
                 unset($question);
@@ -451,7 +450,7 @@ class qformat_webct extends qformat_default {
                 continue;
             }
 
-            if (eregi("^:TYPE:",$line)) {
+            if (preg_match("~^:TYPE:~i",$line)) {
                 // Unknow Question
                 $warnings[] = get_string("unknowntype", "quiz", $nLineCounter);
                 unset($question);
@@ -463,7 +462,7 @@ class qformat_webct extends qformat_default {
                 continue;
             }
 
-            if (eregi("^:TITLE:(.*)",$line,$webct_options)) {
+            if (preg_match("~^:TITLE:(.*)~i",$line,$webct_options)) {
                 $name = trim($webct_options[1]);
                 if (strlen($name) > 255) {
                     $name = substr($name,0,250)."...";
@@ -473,9 +472,9 @@ class qformat_webct extends qformat_default {
                 continue;
             }
 
-            if (eregi("^:IMAGE:(.*)",$line,$webct_options)) {
+            if (preg_match("~^:IMAGE:(.*)~i",$line,$webct_options)) {
                 $filename = trim($webct_options[1]);
-                if (eregi("^http://",$filename)) {
+                if (preg_match("~^http://~i",$filename)) {
                     $question->image = $filename;
                 }
                 continue;
@@ -486,9 +485,9 @@ class qformat_webct extends qformat_default {
             if (!isset($question)) {
                 continue;
             } 
-            if (isset($question->qtype ) && CALCULATED == $question->qtype && ereg(
-                    "^:([[:lower:]].*|::.*)-(MIN|MAX|DEC|VAL([0-9]+))::?:?($webctnumberregex)", $line, $webct_options)) {
-                $datasetname = ereg_replace('^::', '', $webct_options[1]);
+            if (isset($question->qtype ) && CALCULATED == $question->qtype && preg_match(
+                    "~^:([[:lower:]].*|::.*)-(MIN|MAX|DEC|VAL([0-9]+))::?:?($webctnumberregex)~", $line, $webct_options)) {
+                $datasetname = preg_replace('/^::/', '', $webct_options[1]);
                 $datasetvalue = qformat_webct_convert_formula($webct_options[4]);
                 switch ($webct_options[2]) {
                     case 'MIN':
@@ -512,27 +511,27 @@ class qformat_webct extends qformat_default {
             }
 
 
-            $bIsHTMLText = eregi(":H$",$line);  // True if next lines are coded in HTML
-            if (eregi("^:QUESTION",$line)) {
+            $bIsHTMLText = preg_match("~:H$~i",$line);  // True if next lines are coded in HTML
+            if (preg_match("~^:QUESTION~i",$line)) {
                 $questiontext="";               // Start gathering next lines
                 continue;
             }
 
-            if (eregi("^:ANSWER([0-9]+):([^:]+):([0-9\.\-]+):(.*)",$line,$webct_options)) {      /// SHORTANSWER
+            if (preg_match("~^:ANSWER([0-9]+):([^:]+):([0-9\.\-]+):(.*)~i",$line,$webct_options)) {      /// SHORTANSWER
                 $currentchoice=$webct_options[1];
                 $answertext=$webct_options[2];            // Start gathering next lines
                 $question->fraction[$currentchoice]=($webct_options[3]/100);
                 continue;
             }
 
-            if (eregi("^:ANSWER([0-9]+):([0-9\.\-]+)",$line,$webct_options)) {
+            if (preg_match("~^:ANSWER([0-9]+):([0-9\.\-]+)~i",$line,$webct_options)) {
                 $answertext="";                 // Start gathering next lines
                 $currentchoice=$webct_options[1];
                 $question->fraction[$currentchoice]=($webct_options[2]/100);
                 continue;
             }
 
-            if (eregi('^:FORMULA:(.*)', $line, $webct_options)) {
+            if (preg_match('~^:FORMULA:(.*)~i', $line, $webct_options)) {
                 // Answer for a CALCULATED question
                 ++$currentchoice;
                 $question->answers[$currentchoice] =
@@ -556,60 +555,60 @@ class qformat_webct extends qformat_default {
                 continue;
             }
 
-            if (eregi("^:L([0-9]+)",$line,$webct_options)) {
+            if (preg_match("~^:L([0-9]+)~i",$line,$webct_options)) {
                 $answertext="";                 // Start gathering next lines
                 $currentchoice=$webct_options[1];
                 $question->fraction[$currentchoice]=1; 
                 continue;
             }
 
-            if (eregi("^:R([0-9]+)",$line,$webct_options)) {
+            if (preg_match("~^:R([0-9]+)~i",$line,$webct_options)) {
                 $responsetext="";                // Start gathering next lines
                 $currentchoice=$webct_options[1];
                 continue;
             }
 
-            if (eregi("^:REASON([0-9]+):?",$line,$webct_options)) {
+            if (preg_match("~^:REASON([0-9]+):?~i",$line,$webct_options)) {
                 $feedbacktext="";               // Start gathering next lines
                 $currentchoice=$webct_options[1];
                 continue;
             }
-            if (eregi("^:FEEDBACK([0-9]+):?",$line,$webct_options)) {
+            if (preg_match("~^:FEEDBACK([0-9]+):?~i",$line,$webct_options)) {
                 $generalfeedbacktext="";               // Start gathering next lines
                 $currentchoice=$webct_options[1];
                 continue;
             }
-            if (eregi('^:FEEDBACK:(.*)',$line,$webct_options)) {
+            if (preg_match('~^:FEEDBACK:(.*)~i',$line,$webct_options)) {
                 $generalfeedbacktext="";               // Start gathering next lines
                 continue;
             }
-            if (eregi('^:LAYOUT:(.*)',$line,$webct_options)) {
+            if (preg_match('~^:LAYOUT:(.*)~i',$line,$webct_options)) {
             //    ignore  since layout in question_multichoice  is no more used in moodle       
             //    $webct_options[1] contains either vertical or horizontal ;
                 continue;
             }
 
-            if (isset($question->qtype ) && CALCULATED == $question->qtype && eregi('^:ANS-DEC:([1-9][0-9]*)', $line, $webct_options)) {
+            if (isset($question->qtype ) && CALCULATED == $question->qtype && preg_match('~^:ANS-DEC:([1-9][0-9]*)~i', $line, $webct_options)) {
                 // We can but hope that this always appear before the ANSTYPE property
                 $question->correctanswerlength[$currentchoice] = $webct_options[1];
                 continue;
             }
 
-            if (isset($question->qtype )&& CALCULATED == $question->qtype && eregi("^:TOL:($webctnumberregex)", $line, $webct_options)) {
+            if (isset($question->qtype )&& CALCULATED == $question->qtype && preg_match("~^:TOL:($webctnumberregex)~i", $line, $webct_options)) {
                 // We can but hope that this always appear before the TOL property
                 $question->tolerance[$currentchoice] =
                         qformat_webct_convert_formula($webct_options[1]);
                 continue;
             }
 
-            if (isset($question->qtype )&& CALCULATED == $question->qtype && eregi('^:TOLTYPE:percent', $line)) {
+            if (isset($question->qtype )&& CALCULATED == $question->qtype && preg_match('~^:TOLTYPE:percent~i', $line)) {
                 // Percentage case is handled as relative in Moodle:
                 $question->tolerance[$currentchoice]  /= 100;
                 $question->tolerancetype[$currentchoice] = 1; // Relative
                 continue;
             }
 
-            if (eregi('^:UNITS:(.+)', $line, $webct_options)
+            if (preg_match('~^:UNITS:(.+)~i', $line, $webct_options)
                     and $webctunits = trim($webct_options[1])) {
                 // This is a guess - I really do not know how different webct units are separated...
                 $webctunits = explode(':', $webctunits);
@@ -621,7 +620,7 @@ class qformat_webct extends qformat_default {
                 continue;
             }
 
-            if (!empty($question->units) && eregi('^:UNITREQ:(.*)', $line, $webct_options)
+            if (!empty($question->units) && preg_match('~^:UNITREQ:(.*)~i', $line, $webct_options)
                     && !$webct_options[1]) {
                 // There are units but units are not required so add the no unit alternative
                 // We can but hope that the UNITS property always appear before this property
@@ -631,17 +630,17 @@ class qformat_webct extends qformat_default {
                 continue;
             }
 
-            if (!empty($question->units) && eregi('^:UNITCASE:', $line)) {
+            if (!empty($question->units) && preg_match('~^:UNITCASE:~i', $line)) {
                 // This could be important but I was not able to figure out how
                 // it works so I ignore it for now
                 continue;
             }
 
-            if (isset($question->qtype )&& CALCULATED == $question->qtype && eregi('^:ANSTYPE:dec', $line)) {
+            if (isset($question->qtype )&& CALCULATED == $question->qtype && preg_match('~^:ANSTYPE:dec~i', $line)) {
                 $question->correctanswerformat[$currentchoice]='1';
                 continue;
             }
-            if (isset($question->qtype )&& CALCULATED == $question->qtype && eregi('^:ANSTYPE:sig', $line)) {
+            if (isset($question->qtype )&& CALCULATED == $question->qtype && preg_match('~^:ANSTYPE:sig~i', $line)) {
                 $question->correctanswerformat[$currentchoice]='2';
                 continue;
             }
index 33097978574d0763f28b62b003bc5d11c14b9b00..3d3af94696a70df63a3ebb9d8f8da6d1a05c833d 100755 (executable)
@@ -930,7 +930,7 @@ class qformat_xml extends qformat_default {
             foreach($question->options->questions as $question) {
                 $thispattern = addslashes("{#".$a_count."}"); // TODO: fix this addslashes
                 $thisreplace = $question->questiontext;
-                $expout=ereg_replace($thispattern, $thisreplace, $expout );
+                $expout=preg_replace("~$thispattern~", $thisreplace, $expout );
                 $a_count++;
             }
         break;
index b3422b41aed3f048f6af95f49f302115f0f0a611..bc9c49d3248a1a68ba2ed660a5b36d3b320944be 100644 (file)
@@ -169,7 +169,7 @@ class question_edit_calculated_form extends question_edit_form {
             $qtextremaining = str_replace('{'.$name.'}', '1', $qtextremaining);
         }
     //     echo "numericalquestion qtextremaining <pre>";print_r($possibledatasets);
-        while  (ereg('\{=([^[:space:]}]*)}', $qtextremaining, $regs1)) {
+        while  (preg_match('~\{=([^[:space:]}]*)}~', $qtextremaining, $regs1)) {
             $qtextsplits = explode($regs1[0], $qtextremaining, 2);
             $qtext =$qtext.$qtextsplits[0];
             $qtextremaining = $qtextsplits[1];
@@ -274,4 +274,4 @@ class question_edit_calculated_form extends question_edit_form {
         return $errors;
     }
 }
-?>
\ No newline at end of file
+?>
index c31aec4fd4d6cd531ccdd4e3743c9eb5156f79d7..4cf8596c7e1a314eb3c31f727f28dbe997f431f7 100644 (file)
@@ -267,7 +267,7 @@ class question_calculated_qtype extends default_questiontype {
     }
 
     function restore_session_and_responses(&$question, &$state) {
-        if (!ereg('^dataset([0-9]+)[^-]*-(.*)$',
+        if (!preg_match('~^dataset([0-9]+)[^-]*-(.*)$~',
                 $state->responses[''], $regs)) {
             notify ("Wrongly formatted raw response answer " .
                    "{$state->responses['']}! Could not restore session for " .
@@ -647,7 +647,7 @@ class question_calculated_qtype extends default_questiontype {
         //evaluate the equations i.e {=5+4)
         $qtext = "";
         $qtextremaining = $numericalquestion->questiontext ;
-        while  (ereg('\{=([^[:space:]}]*)}', $qtextremaining, $regs1)) {
+        while  (preg_match('~\{=([^[:space:]}]*)}~', $qtextremaining, $regs1)) {
             $qtextsplits = explode($regs1[0], $qtextremaining, 2);
             $qtext =$qtext.$qtextsplits[0];
             $qtextremaining = $qtextsplits[1];
@@ -766,7 +766,7 @@ class question_calculated_qtype extends default_questiontype {
     function custom_generator_set_data($datasetdefs, $formdata){
         $idx = 1;
         foreach ($datasetdefs as $datasetdef){
-            if (ereg('^(uniform|loguniform):([^:]*):([^:]*):([0-9]*)$', $datasetdef->options, $regs)) {
+            if (preg_match('~^(uniform|loguniform):([^:]*):([^:]*):([0-9]*)$~', $datasetdef->options, $regs)) {
                 $defid = "$datasetdef->type-$datasetdef->category-$datasetdef->name";
                 $formdata["calcdistribution[$idx]"] = $regs[1];
                 $formdata["calcmin[$idx]"] = $regs[2];
@@ -779,7 +779,7 @@ class question_calculated_qtype extends default_questiontype {
     }
 
     function custom_generator_tools($datasetdef) {
-        if (ereg('^(uniform|loguniform):([^:]*):([^:]*):([0-9]*)$',
+        if (preg_match('~^(uniform|loguniform):([^:]*):([^:]*):([0-9]*)$~',
                 $datasetdef->options, $regs)) {
             $defid = "$datasetdef->type-$datasetdef->category-$datasetdef->name";
             for ($i = 0 ; $i<10 ; ++$i) {
@@ -1012,7 +1012,7 @@ class question_calculated_qtype extends default_questiontype {
        }
     }
     function generate_dataset_item($options) {
-        if (!ereg('^(uniform|loguniform):([^:]*):([^:]*):([0-9]*)$',
+        if (!preg_match('~^(uniform|loguniform):([^:]*):([^:]*):([0-9]*)$~',
                 $options, $regs)) {
             // Unknown options...
             return false;
@@ -1122,7 +1122,7 @@ class question_calculated_qtype extends default_questiontype {
   //  list($options, $selected) = $this->dataset_optionsa($form, $name);
 
         foreach ($options as $key => $whatever) {
-            if (!ereg('^1-', $key) && $key != '0') {
+            if (!preg_match('~^1-~', $key) && $key != '0') {
                 unset($options[$key]);
             }
         }
@@ -1495,7 +1495,7 @@ class question_calculated_qtype extends default_questiontype {
     /// Returns the possible dataset names found in the text as an array
     /// The array has the dataset name for both key and value
         $datasetnames = array();
-        while (ereg('\\{([[:alpha:]][^>} <{"\']*)\\}', $text, $regs)) {
+        while (preg_match('~\\{([[:alpha:]][^>} <{"\']*)\\}~', $text, $regs)) {
             $datasetnames[$regs[1]] = $regs[1];
             $text = str_replace($regs[0], '', $text);
         }
@@ -1781,7 +1781,7 @@ function qtype_calculated_calculate_answer($formula, $individualdata,
         if ($answerlength) {
             /* Try to include missing zeros at the end */
 
-            if (ereg('^(.*\\.)(.*)$', $calculated->answer, $regs)) {
+            if (preg_match('~^(.*\\.)(.*)$~', $calculated->answer, $regs)) {
                 $calculated->answer = $regs[1] . substr(
                         $regs[2] . '00000000000000000000000000000000000000000x',
                         0, $answerlength)
@@ -1841,7 +1841,7 @@ function qtype_calculated_calculate_answer($formula, $individualdata,
                 $calculated->answer = $sign.$answer.$unit;
             } else {
                 // Could be an idea to add some zeros here
-                $answer .= (ereg('^[0-9]*$', $answer) ? '.' : '')
+                $answer .= (preg_match('~^[0-9]*$~', $answer) ? '.' : '')
                         . '00000000000000000000000000000000000000000x';
                 $oklen = $answerlength + ($p10 < 1 ? 2-$p10 : 1);
                 $calculated->answer = $sign.substr($answer, 0, $oklen).$unit;
@@ -1862,7 +1862,7 @@ function qtype_calculated_find_formula_errors($formula) {
 /// Returns false if everything is alright.
 /// Otherwise it constructs an error message
     // Strip away dataset names
-    while (ereg('\\{[[:alpha:]][^>} <{"\']*\\}', $formula, $regs)) {
+    while (preg_match('~\\{[[:alpha:]][^>} <{"\']*\\}~', $formula, $regs)) {
         $formula = str_replace($regs[0], '1', $formula);
     }
 
@@ -1873,7 +1873,7 @@ function qtype_calculated_find_formula_errors($formula) {
     $operatorornumber = "[$safeoperatorchar.0-9eE]";
 
 
-    while (ereg("(^|[$safeoperatorchar,(])([a-z0-9_]*)\\(($operatorornumber+(,$operatorornumber+((,$operatorornumber+)+)?)?)?\\)",
+    while (preg_match("~(^|[$safeoperatorchar,(])([a-z0-9_]*)\\(($operatorornumber+(,$operatorornumber+((,$operatorornumber+)+)?)?)?\\)~",
             $formula, $regs)) {
 
         switch ($regs[2]) {
@@ -1936,11 +1936,11 @@ function qtype_calculated_find_formula_errors($formula) {
             $formula = str_replace($regs[0], $regs[1] . '1', $formula);
         } else {
             // The function call starts the formula
-            $formula = ereg_replace("^$regs[2]\\([^)]*\\)", '1', $formula);
+            $formula = preg_replace("~^$regs[2]\\([^)]*\\)~", '1', $formula);
         }
     }
 
-    if (ereg("[^$safeoperatorchar.0-9eE]+", $formula, $regs)) {
+    if (preg_match("~[^$safeoperatorchar.0-9eE]+~", $formula, $regs)) {
         return get_string('illegalformulasyntax', 'quiz', $regs[0]);
     } else {
         // Formula just might be valid
index 251453d99c355d57a219d6b8c2addf41d19ae64f..f41f7502160da1032a50a178f28ad9eb688b958b 100644 (file)
@@ -161,7 +161,7 @@ class question_edit_calculatedsimple_form extends question_edit_form {
                 $this->datasetdefs[$def]->calcmax = $calcmax[$key] ;
                 $this->datasetdefs[$def]->calclength = $calclength[$key] ;
                 //then compare with new values
-                if (ereg('^(uniform|loguniform):([^:]*):([^:]*):([0-9]*)$', $this->datasetdefs[$def]->options, $regs)) {
+                if (preg_match('~^(uniform|loguniform):([^:]*):([^:]*):([0-9]*)$~', $this->datasetdefs[$def]->options, $regs)) {
                    if( $this->datasetdefs[$def]->calcmin != $regs[2]||
                     $this->datasetdefs[$def]->calcmax != $regs[3] ||
                     $this->datasetdefs[$def]->calclength != $regs[4]){
@@ -667,7 +667,7 @@ class question_edit_calculatedsimple_form extends question_edit_form {
             foreach ($possibledatasets as $name => $value) {
             $qtextremaining = str_replace('{'.$name.'}', '1', $qtextremaining);
         }
-        while  (ereg('\{=([^[:space:]}]*)}', $qtextremaining, $regs1)) {
+        while  (preg_match('~\{=([^[:space:]}]*)}~', $qtextremaining, $regs1)) {
             $qtextsplits = explode($regs1[0], $qtextremaining, 2);
             $qtext =$qtext.$qtextsplits[0];
             $qtextremaining = $qtextsplits[1];
@@ -799,4 +799,4 @@ class question_edit_calculatedsimple_form extends question_edit_form {
         return $errors;
     }
 }
-?>
\ No newline at end of file
+?>
index 08fd8438ff23dc53b63c7af91571454db888906d..ae001db7d97c8e9f0677f2a2638f76e6464bb3f0 100644 (file)
@@ -332,7 +332,7 @@ class question_calculatedsimple_qtype extends question_calculated_qtype {
   //  list($options, $selected) = $this->dataset_optionsa($form, $name);
 
         foreach ($options as $key => $whatever) {
-            if (!ereg('^1-', $key) && $key != '0') {
+            if (!preg_match('~^1-~', $key) && $key != '0') {
                 unset($options[$key]);
             }
         }
index d534fbf842299a0ea9a1142d16041cabe0a93de7..eeb5f96edbd68089930b3a494fa317de52931efa 100644 (file)
@@ -307,7 +307,7 @@ class embedded_cloze_qtype extends default_questiontype {
         // The regex will recognize text snippets of type {#X}
         // where the X can be any text not containg } or white-space characters.
 
-        while (ereg('\{#([^[:space:]}]*)}', $qtextremaining, $regs)) {
+        while (preg_match('~\{#([^[:space:]}]*)}~', $qtextremaining, $regs)) {
             $qtextsplits = explode($regs[0], $qtextremaining, 2);
             echo $qtextsplits[0];
             echo "<label>"; // MDL-7497
@@ -1047,7 +1047,7 @@ function qtype_multianswer_extract_question($text) {
                 $wrapped->feedback[] = '';
             }
             if (!empty($answerregs[ANSWER_REGEX_ANSWER_TYPE_NUMERICAL])
-                    && ereg(NUMERICAL_ALTERNATIVE_REGEX, $altregs[ANSWER_ALTERNATIVE_REGEX_ANSWER], $numregs)) {
+                    && preg_match('~'.NUMERICAL_ALTERNATIVE_REGEX.'~', $altregs[ANSWER_ALTERNATIVE_REGEX_ANSWER], $numregs)) {
                 $wrapped->answer[] = $numregs[NUMERICAL_CORRECT_ANSWER];
                 if ($numregs[NUMERICAL_ABS_ERROR_MARGIN]) {
                     $wrapped->tolerance[] =
index 45886361a231cc27630c30c8854905cad714e2f6..ed3cf4a84e33bac6801d7ca306ed67e6a09e834e 100644 (file)
@@ -366,7 +366,7 @@ class question_numerical_qtype extends question_shortanswer_qtype {
         $rawresponse = str_replace($search, $replace, trim($rawresponse));
 
         // Apply any unit that is present.
-        if (ereg('^([+-]?([0-9]+(\\.[0-9]*)?|\\.[0-9]+)([eE][-+]?[0-9]+)?)([^0-9].*)?$',
+        if (preg_match('~^([+-]?([0-9]+(\\.[0-9]*)?|\\.[0-9]+)([eE][-+]?[0-9]+)?)([^0-9].*)?$~',
                 $rawresponse, $responseparts)) {
 
             if (!empty($responseparts[5])) {
index b5dfe69a8dd9870ffbc2ad9677d0af7657089304..0a148fe9fd0460eeb01d195fa424a8e60a60b7e2 100644 (file)
@@ -189,7 +189,7 @@ class random_qtype extends default_questiontype {
 
         while ($wrappedquestion = array_pop(
                 $this->catrandoms[$question->category][$question->questiontext])) {
-            if (!ereg("(^|,)$wrappedquestion->id(,|$)", $cmoptions->questionsinuse)) {
+            if (!preg_match("~(^|,)$wrappedquestion->id(,|$)~", $cmoptions->questionsinuse)) {
                 /// $randomquestion is not in use and will therefore be used
                 /// as the randomquestion here...
                 $wrappedquestion = $DB->get_record('question', array('id' => $wrappedquestion->id));
@@ -231,7 +231,7 @@ class random_qtype extends default_questiontype {
         /// the other question types in that it now only needs one response
         /// record per question.
         global $QTYPES, $DB;
-        if (!ereg('^random([0-9]+)-(.*)$', $state->responses[''], $answerregs)) {
+        if (!preg_match('~^random([0-9]+)-(.*)$~', $state->responses[''], $answerregs)) {
             if (empty($state->responses[''])) {
                 // This is the case if there weren't enough questions available in the category.
                 $question->questiontext = '<span class="notifyproblem">'.
@@ -375,7 +375,7 @@ class random_qtype extends default_questiontype {
         global $QTYPES, $DB;
         $answer_field = "";
 
-        if (ereg('^random([0-9]+)-(.*)$', $state->answer, $answerregs)) {
+        if (preg_match('~^random([0-9]+)-(.*)$~', $state->answer, $answerregs)) {
             // Recode the question id in $answerregs[1]
             // Get the question from backup_ids
             if(!$wrapped = backup_getid($restore->backup_unique_code,"question",$answerregs[1])) {
index caf5f007a54ca0e03a39f3ad2e9e6237458c0c7a..51fbece232575dd00baa3c91648e2168ec720b54 100644 (file)
@@ -145,7 +145,7 @@ function assignment_get_content_for_index(&$assignment) {
                 } elseif ($submitted->source = 'files'){
                     $SUBMITTED = opendir($submitted->path);
                     while($entry = readdir($SUBMITTED)){
-                        if (ereg("^\.", $entry)) continue; // exclude hidden and dirs . and .. 
+                        if (preg_match("/^\./", $entry)) continue; // exclude hidden and dirs . and .. 
                         $path = "{$submitted->path}/{$entry}";
                         $documents[] = assignment_get_physical_file($submission, $assignment, $cm, $path, $context_id, $documents);
                         mtrace("finished attachement $path for {$submission->authors} in assignement {$assignment->name}");
@@ -373,4 +373,4 @@ function assignment_link_post_processing($title){
     }
     return mb_convert_encoding($title, 'auto', 'UTF-8');
 }
-?>
\ No newline at end of file
+?>
index c7f09108fc11ef30d882a9321f94fc4c5ad30ff5..f3ae17d58e0a8f3b557913eb69025c25bdc5fc8d 100644 (file)
@@ -134,7 +134,7 @@ class user_editadvanced_form extends moodleform {
                 $err['username'] = get_string('usernamelowercase');
             } else {
                 if (empty($CFG->extendedusernamechars)) {
-                    $string = eregi_replace("[^(-\.[:alnum:])]", '', $usernew->username);
+                    $string = preg_replace("/[^(-\.[:alnum:])]/i", '', $usernew->username);
                     if ($usernew->username !== $string) {
                         $err['username'] = get_string('alphanumerical');
                     }