Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Replace ereg with preg_*

  • Loading branch information...
commit 0e2cbb0b88cf3913d850942992448d3c4a0ffd70 1 parent edf6cd6
@AngryPHPNerd AngryPHPNerd authored
View
8 control/ContentNegotiator.php
@@ -143,7 +143,7 @@ function xhtml(SS_HTTPResponse $response) {
$content = str_replace(' ',' ', $content);
$content = str_replace('<br>','<br />', $content);
- $content = eregi_replace('(<img[^>]*[^/>])>','\\1/>', $content);
+ $content = preg_replace('#(<img[^>]*[^/>])>#i', '\\1/>', $content);
$response->setBody($content);
@@ -170,14 +170,14 @@ function html(SS_HTTPResponse $response) {
$content = preg_replace('/<base href="([^"]*)" \/>/',
'<base href="$1"><!--[if lte IE 6]></base><![endif]-->', $content);
- $content = ereg_replace("<\\?xml[^>]+\\?>\n?",'',$content);
+ $content = preg_replace("#<\\?xml[^>]+\\?>\n?#", '', $content);
$content = str_replace(array('/>','xml:lang','application/xhtml+xml'),array('>','lang','text/html'), $content);
// Only replace the doctype in templates with the xml header
if($hasXMLHeader) {
- $content = ereg_replace('<!DOCTYPE[^>]+>', '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">', $content);
+ $content = preg_replace('/<!DOCTYPE[^>]+>/', '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">', $content);
}
- $content = ereg_replace('<html xmlns="[^"]+"','<html ', $content);
+ $content = preg_replace('/<html xmlns="[^"]+"/','<html ', $content);
$response->setBody($content);
}
View
4 control/Director.php
@@ -465,7 +465,7 @@ static function setBaseFolder($baseFolder) {
*/
static function makeRelative($url) {
// Allow for the accidental inclusion of a // in the URL
- $url = ereg_replace('([^:])//','\\1/',$url);
+ $url = preg_replace('#([^:])//#', '\\1/', $url);
$url = trim($url);
// Only bother comparing the URL to the absolute version if $url looks like a URL.
@@ -866,4 +866,4 @@ static function isTest() {
return false;
}
-}
+}
View
2  control/HTTP.php
@@ -38,7 +38,7 @@ static function filename2url($filename) {
*/
static function absoluteURLs($html) {
$html = str_replace('$CurrentPageURL', $_SERVER['REQUEST_URI'], $html);
- return HTTP::urlRewriter($html, '(substr($URL,0,1) == "/") ? ( Director::protocolAndHost() . $URL ) : ( (ereg("^[A-Za-z]+:", $URL)) ? $URL : Director::absoluteBaseURL() . $URL )' );
+ return HTTP::urlRewriter($html, '(substr($URL,0,1) == "/") ? ( Director::protocolAndHost() . $URL ) : ( (preg_match("/^[A-Za-z]+:/", $URL)) ? $URL : Director::absoluteBaseURL() . $URL )' );
}
/*
View
27 core/Convert.php
@@ -291,26 +291,25 @@ static function html2raw($data, $preserveLinks = false, $wordWrap = 60, $config
// Replace images with their alt tags
if($config['ReplaceImagesWithAlt']) {
- $data = eregi_replace('<img[^>]*alt *= *"([^"]*)"[^>]*>', ' \\1 ', $data);
- $data = eregi_replace('<img[^>]*alt *= *([^ ]*)[^>]*>', ' \\1 ', $data);
+ $data = preg_replace('/<img[^>]*alt *= *"([^"]*)"[^>]*>/i', ' \\1 ', $data);
+ $data = preg_replace('/<img[^>]*alt *= *([^ ]*)[^>]*>/i', ' \\1 ', $data);
}
// Compress whitespace
if($config['CompressWhitespace']) {
- $data = ereg_replace("[\n\r\t ]+", " ", $data);
+ $data = preg_replace("/\s+/", " ", $data);
}
// Parse newline tags
- $data = ereg_replace("[ \n\r\t]*<[Hh][1-6]([^A-Za-z0-9>][^>]*)?> *", "\n\n", $data);
- $data = ereg_replace("[ \n\r\t]*<[Pp]([^A-Za-z0-9>][^>]*)?> *", "\n\n", $data);
- $data = ereg_replace("[ \n\r\t]*<[Dd][Ii][Vv]([^A-Za-z0-9>][^>]*)?> *", "\n\n", $data);
- $data = ereg_replace("\n\n\n+","\n\n", $data);
-
- $data = ereg_replace("<[Bb][Rr]([^A-Za-z0-9>][^>]*)?> *", "\n", $data);
- $data = ereg_replace("<[Tt][Rr]([^A-Za-z0-9>][^>]*)?> *", "\n", $data);
- $data = ereg_replace("</[Tt][Dd]([^A-Za-z0-9>][^>]*)?> *", " ", $data);
+ $data = preg_replace("/\s*<[Hh][1-6]([^A-Za-z0-9>][^>]*)?> */", "\n\n", $data);
+ $data = preg_replace("/\s*<[Pp]([^A-Za-z0-9>][^>]*)?> */", "\n\n", $data);
+ $data = preg_replace("/\s*<[Dd][Ii][Vv]([^A-Za-z0-9>][^>]*)?> */", "\n\n", $data);
+ $data = preg_replace("/\n\n\n+/", "\n\n", $data);
+
+ $data = preg_replace("/<[Bb][Rr]([^A-Za-z0-9>][^>]*)?> */", "\n", $data);
+ $data = preg_replace("/<[Tt][Rr]([^A-Za-z0-9>][^>]*)?> */", "\n", $data);
+ $data = preg_replace("/</[Tt][Dd]([^A-Za-z0-9>][^>]*)?> */", " ", $data);
$data = preg_replace('/<\/p>/i', "\n\n", $data );
-
// Replace HTML entities
//$data = preg_replace("/&#([0-9]+);/e", 'chr(\1)', $data);
@@ -327,7 +326,7 @@ static function html2raw($data, $preserveLinks = false, $wordWrap = 60, $config
}
return trim(wordwrap(trim($data), $wordWrap));
}
-
+
/**
* There are no real specifications on correctly encoding mailto-links,
* but this seems to be compatible with most of the user-agents.
@@ -358,4 +357,4 @@ public static function raw2url($title) {
$f = Object::create('URLSegmentFilter');
return $f->filter($title);
}
-}
+}
View
2  dev/SapphireTestReporter.php
@@ -257,7 +257,7 @@ public function endTestSuite( PHPUnit_Framework_TestSuite $suite) {
*/
private function getTestException(PHPUnit_Framework_Test $test, Exception $e) {
// get the name of the testFile from the test
- $testName = ereg_replace('(.*)\((.*[^)])\)', '\\2', $test->toString());
+ $testName = preg_replace('/(.*)\((.*[^)])\)/', '\\2', $test->toString());
$trace = $e->getTrace();
// loop through the exception trace to find the original exception
for($i = 0; $i < count($trace); $i++) {
View
10 email/Email.php
@@ -360,9 +360,13 @@ protected function parseVariables($isPlain = false) {
* @desc Validates the email address. Returns true of false
*/
static function validEmailAddress($address) {
- return ereg('^([a-zA-Z0-9_+\.\-]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$', $address);
+ if (function_exists('filter_var')) {
+ return filter_var($address, FILTER_VALIDATE_EMAIL);
+ } else {
+ return preg_match('#^([a-zA-Z0-9_+\.\-]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$#', $address);
+ }
}
-
+
/**
* Send the email in plaintext.
*
@@ -658,7 +662,7 @@ function index() {
}
private function recordBounce( $email, $date = null, $time = null, $error = null ) {
- if(ereg('<(.*)>', $email, $parts)) $email = $parts[1];
+ if(preg_match('/<(.*)>/', $email, $parts)) $email = $parts[1];
$SQL_email = Convert::raw2sql($email);
$SQL_bounceTime = Convert::raw2sql("$date $time");
View
9 email/Mailer.php
@@ -134,8 +134,8 @@ function htmlEmail($to, $from, $subject, $htmlContent, $attachedFiles = false, $
}
// Strip the human name from the bounce address
- if(ereg('^([^<>]*)<([^<>]+)> *$', $bounceAddress, $parts)) $bounceAddress = $parts[2];
-
+ if(preg_match('/^([^<>]*)<([^<>]+)> *$/', $bounceAddress, $parts)) $bounceAddress = $parts[2];
+
// $headers["Sender"] = $from;
$headers["X-Mailer"] = X_MAILER;
if (!isset($customheaders["X-Priority"])) $headers["X-Priority"] = 3;
@@ -215,7 +215,7 @@ function plaintextEmail($to, $from, $subject, $plainContent, $attachedFiles, $cu
if(isset($customheaders["X-SilverStripeMessageID"]) && defined('BOUNCE_EMAIL')) {
$bounceAddress = BOUNCE_EMAIL;
// Get the human name from the from address, if there is one
- if(ereg('^([^<>]+)<([^<>])> *$', $from, $parts))
+ if(preg_match('/^([^<>]+)<([^<>])> *$/', $from, $parts))
$bounceAddress = "$parts[1]<$bounceAddress>";
} else {
$bounceAddress = $from;
@@ -249,8 +249,7 @@ function plaintextEmail($to, $from, $subject, $plainContent, $attachedFiles, $cu
function encodeMultipart($parts, $contentType, $headers = false) {
- $separator = "----=_NextPart_" . ereg_replace('[^0-9]','',rand() * 10000000000);
-
+ $separator = "----=_NextPart_" . preg_replace('/[^0-9]/', '', rand() * 10000000000);
$headers["MIME-Version"] = "1.0";
$headers["Content-Type"] = "$contentType; boundary=\"$separator\"";
View
4 filesystem/File.php
@@ -144,7 +144,7 @@ class File extends DataObject {
*/
static function find($filename) {
// Get the base file if $filename points to a resampled file
- $filename = ereg_replace('_resampled/[^-]+-','',$filename);
+ $filename = preg_replace('/_resampled/[^-]+-/', '', $filename);
// Split to folders and the actual filename, and traverse the structure.
$parts = explode("/", $filename);
@@ -483,7 +483,7 @@ function setName($name) {
}
// Update title
- if(!$this->getField('Title')) $this->__set('Title', str_replace(array('-','_'),' ',ereg_replace('\.[^.]+$','',$name)));
+ if(!$this->getField('Title')) $this->__set('Title', str_replace(array('-','_'),' ', preg_replace('/\.[^.]+$/', '', $name)));
// Update actual field value
$this->setField('Name', $name);
View
8 filesystem/Folder.php
@@ -261,13 +261,13 @@ function addUploadToFolder($tmpFile) {
$oldFile = $file;
if(strpos($file, '.') !== false) {
- $file = ereg_replace('[0-9]*(\.[^.]+$)', $i . '\\1', $file);
+ $file = preg_replace('/[0-9]*(\.[^.]+$)/', $i . '\\1', $file);
} elseif(strpos($file, '_') !== false) {
- $file = ereg_replace('_([^_]+$)', '_' . $i, $file);
+ $file = preg_replace('/_([^_]+$)/', '_' . $i, $file);
} else {
- $file .= "_$i";
+ $file .= '_'.$i;
}
-
+
if($oldFile == $file && $i > 2) user_error("Couldn't fix $file$ext with $i", E_USER_ERROR);
}
View
10 filesystem/Upload.php
@@ -144,13 +144,13 @@ function load($tmpFile, $folderPath = false) {
// make sure archives retain valid extensions
if(substr($relativeFilePath, strlen($relativeFilePath) - strlen('.tar.gz')) == '.tar.gz' ||
substr($relativeFilePath, strlen($relativeFilePath) - strlen('.tar.bz2')) == '.tar.bz2') {
- $relativeFilePath = ereg_replace('[0-9]*(\.tar\.[^.]+$)',$i . '\\1', $relativeFilePath);
+ $relativeFilePath = preg_replace('/[0-9]*(\.tar\.[^.]+$)/', $i . '\\1', $relativeFilePath);
} else if (strpos($relativeFilePath, '.') !== false) {
- $relativeFilePath = ereg_replace('[0-9]*(\.[^.]+$)',$i . '\\1', $relativeFilePath);
+ $relativeFilePath = preg_replace('/[0-9]*(\.[^.]+$)/', $i . '\\1', $relativeFilePath);
} else if (strpos($relativeFilePath, '_') !== false) {
- $relativeFilePath = ereg_replace('_([^_]+$)', '_'.$i, $relativeFilePath);
+ $relativeFilePath = preg_replace('/_([^_]+$)/', '_'.$i, $relativeFilePath);
} else {
- $relativeFilePath .= "_$i";
+ $relativeFilePath .= '_'.$i;
}
if($oldFilePath == $relativeFilePath && $i > 2) user_error("Couldn't fix $relativeFilePath with $i tries", E_USER_ERROR);
}
@@ -525,4 +525,4 @@ public function validate() {
return true;
}
-}
+}
View
2  forms/CreditCardField.php
@@ -86,7 +86,7 @@ function validate($validator){
$i=0;
if($this->value) foreach($this->value as $part){
- if(!$part || !(strlen($part) == 4) || !ereg("([0-9]{4})",$part)){
+ if(!$part || !(strlen($part) == 4) || !preg_match("/([0-9]{4})/", $part)){
switch($i){
case 0: $number = _t('CreditCardField.FIRST', 'first'); break;
case 1: $number = _t('CreditCardField.SECOND', 'second'); break;
View
6 forms/FieldGroup.php
@@ -79,12 +79,12 @@ function Name(){
if($subfield->getName()) $count++;
}
if($count == 1) $compositeTitle .= 'Group';
- return ereg_replace("[^a-zA-Z0-9]+","",$compositeTitle);
+ return preg_replace("/[^a-zA-Z0-9]+/", "", $compositeTitle);
}
- return ereg_replace("[^a-zA-Z0-9]+","",$this->title);
+ return preg_replace("/[^a-zA-Z0-9]+/", "", $this->title);
}
-
+
/**
* Returns a set of <span class="subfield"> tags, each containing a sub-field.
* You can also use <% control FieldSet %>, if you'd like more control over the generated HTML
View
6 forms/FormField.php
@@ -123,7 +123,7 @@ function Link($action = null) {
* that this ID is included in the field.
*/
function ID() {
- $name = ereg_replace('(^-)|(-$)','',ereg_replace('[^A-Za-z0-9_-]+','-',$this->name));
+ $name = preg_replace('/(^-)|(-$)/', '', preg_replace('/[^A-Za-z0-9_-]+/', '-', $this->name));
if($this->form) return $this->form->FormName() . '_' . $name;
else return $name;
}
@@ -648,7 +648,7 @@ function hasClass($class){
* @return string
*/
function Type() {
- return strtolower(ereg_replace('Field$', '', $this->class));
+ return strtolower(preg_replace('/Field$/', '', $this->class));
}
/**
@@ -769,4 +769,4 @@ function rootFieldSet() {
else user_error("rootFieldSet() called on $this->class object without a containerFieldSet", E_USER_ERROR);
}
-}
+}
View
4 forms/HtmlEditorField.php
@@ -425,7 +425,7 @@ public function viewfile($request) {
$file = null;
} else {
$url = Director::makeRelative($request->getVar('FileURL'));
- $url = ereg_replace('_resampled/[^-]+-','',$url);
+ $url = preg_replace('/_resampled/[^-]+-/', '', $url);
$file = DataList::create('File')->filter('Filename', $url)->first();
if(!$file) $file = new File(array('Title' => basename($url)));
}
@@ -663,4 +663,4 @@ function getPreview() {
return ($this->file) ? $this->file->CMSThumbnail() : sprintf('<img src="%s" />', $this->url);
}
-}
+}
View
17 i18n/i18nTextCollector.php
@@ -191,15 +191,15 @@ protected function processModule($module) {
public function collectFromCode($content, $module) {
$entitiesArr = array();
- $regexRule = '_t[[:space:]]*\(' .
+ $regexRule = '#_t[[:space:]]*\(' .
'[[:space:]]*("[^"]*"|\\\'[^\']*\\\')[[:space:]]*,' . // namespace.entity
'[[:space:]]*(("([^"]|\\\")*"|\'([^\']|\\\\\')*\')' . // value
'([[:space:]]*\\.[[:space:]]*("([^"]|\\\")*"|\'([^\']|\\\\\')*\'))*)' . // concatenations
'([[:space:]]*,[[:space:]]*[^,)]*)?([[:space:]]*,' . // priority (optional)
'[[:space:]]*("([^"]|\\\")*"|\'([^\']|\\\\\')*\'))?[[:space:]]*' . // comment (optional)
- '\)';
-
- while (ereg($regexRule, $content, $regs)) {
+ '\)#';
+
+ while (preg_match($regexRule, $content, $regs)) {
$entitiesArr = array_merge($entitiesArr, (array)$this->entitySpecFromRegexMatches($regs));
// remove parsed content to continue while() loop
@@ -229,14 +229,15 @@ public function collectFromTemplate($content, $module, $fileName) {
}
// @todo respect template tags (< % _t() % > instead of _t())
- $regexRule = '_t[[:space:]]*\(' .
+ $regexRule = '#_t[[:space:]]*\(' .
'[[:space:]]*("[^"]*"|\\\'[^\']*\\\')[[:space:]]*,' . // namespace.entity
'[[:space:]]*(("([^"]|\\\")*"|\'([^\']|\\\\\')*\')' . // value
'([[:space:]]*\\.[[:space:]]*("([^"]|\\\")*"|\'([^\']|\\\\\')*\'))*)' . // concatenations
'([[:space:]]*,[[:space:]]*[^,)]*)?([[:space:]]*,' . // priority (optional)
'[[:space:]]*("([^"]|\\\")*"|\'([^\']|\\\\\')*\'))?[[:space:]]*' . // comment (optional)
- '\)';
- while(ereg($regexRule,$content,$regs)) {
+ '\)#';
+
+ while (preg_match($regexRule,$content,$regs)) {
$entitiesArr = array_merge($entitiesArr,(array)$this->entitySpecFromRegexMatches($regs, $fileName));
// remove parsed content to continue while() loop
$content = str_replace($regs[0],"",$content);
@@ -301,7 +302,7 @@ protected function entitySpecFromRegexMatches($regs, $_namespace = null) {
// remove wrapping quotes
$value = ($regs[2]) ? substr($regs[2],1,-1) : null;
- $value = ereg_replace("([^\\])['\"][[:space:]]*\.[[:space:]]*['\"]",'\\1',$value);
+ $value = preg_replace("/([^\\])['\"][[:space:]]*\.[[:space:]]*['\"]/", '\\1', $value);
// only escape quotes when wrapped in double quotes, to make them safe for insertion
// into single-quoted PHP code. If they're wrapped in single quotes, the string should
View
11 model/Database.php
@@ -395,8 +395,9 @@ function requireIndex($table, $index, $spec) {
}
//Indexes specified as arrays cannot be checked with this line: (it flattens out the array)
- if(!is_array($spec))
- $spec = ereg_replace(" *, *",",",$spec);
+ if(!is_array($spec)) {
+ $spec = preg_replace('/\s*,\s*/', ',', $spec);
+ }
if(!isset($this->tableList[strtolower($table)])) $newTable = true;
@@ -470,7 +471,7 @@ function requireField($table, $field, $spec) {
// collations.
// TODO: move this to the MySQLDatabase file, or drop it altogether?
if(!$this->supportsCollations()) {
- $spec = eregi_replace(' *character set [^ ]+( collate [^ ]+)?( |$)','\\2',$spec);
+ $spec = preg_replace('/ *character set [^ ]+( collate [^ ]+)?( |$)/', '\\2', $spec);
}
if(!isset($this->tableList[strtolower($table)])) $newTable = true;
@@ -632,8 +633,8 @@ function manipulate($manipulation) {
* @param string $array Array where the replacement should happen
*/
static function replace_with_null(&$array) {
- $array = ereg_replace('= *\'\'', "= null", $array);
-
+ $array = preg_replace('/= *\'\'/', '= null', $array);
+
if(is_array($array)) {
foreach($array as $key => $value) {
if(is_array($value)) {
View
2  model/Image.php
@@ -172,7 +172,7 @@ function loadUploadedImage($tmpFile) {
while(file_exists(BASE_PATH . "/$file")) {
$i = $i ? ($i+1) : 2;
$oldFile = $file;
- $file = ereg_replace('[0-9]*(\.[^.]+$)',$i . '\\1', $file);
+ $file = preg_replace('/[0-9]*(\.[^.]+$)/', $i . '\\1', $file);
if($oldFile == $file && $i > 2) user_error("Couldn't fix $file with $i", E_USER_ERROR);
}
View
6 model/fieldtypes/Date.php
@@ -30,10 +30,10 @@ function setValue($value) {
}
// Default to NZ date format - strtotime expects a US date
- if(ereg('^([0-9]+)/([0-9]+)/([0-9]+)$', $value, $parts)) {
+ if(preg_match('#^([0-9]+)/([0-9]+)/([0-9]+)$#', $value, $parts)) {
$value = "$parts[2]/$parts[1]/$parts[3]";
}
-
+
if(is_numeric($value)) {
$this->value = date('Y-m-d', $value);
} elseif(is_string($value)) {
@@ -357,4 +357,4 @@ static function past_date($fmonth, $fday = 1, $fyear = null) {
public function scaffoldFormField($title = null, $params = null) {
return new DateField($this->name, $title);
}
-}
+}
View
4 model/fieldtypes/Datetime.php
@@ -27,10 +27,10 @@ class SS_Datetime extends Date {
function setValue($value) {
// Default to NZ date format - strtotime expects a US date
- if(ereg('^([0-9]+)/([0-9]+)/([0-9]+)$', $value, $parts)) {
+ if(preg_match('#^([0-9]+)/([0-9]+)/([0-9]+)$#', $value, $parts)) {
$value = "$parts[2]/$parts[1]/$parts[3]";
}
-
+
if(is_numeric($value)) {
$this->value = date('Y-m-d H:i:s', $value);
} elseif(is_string($value)) {
View
2  model/fieldtypes/Varchar.php
@@ -63,7 +63,7 @@ function Initial() {
* Ensure that the given value is an absolute URL.
*/
function URL() {
- if(ereg('^[a-zA-Z]+://', $this->value)) return $this->value;
+ if(preg_match('#^[a-zA-Z]+://#', $this->value)) return $this->value;
else return "http://" . $this->value;
}
View
4 security/PermissionCheckboxSetField.php
@@ -180,7 +180,7 @@ function Field() {
$odd = ($odd + 1) % 2;
$extraClass = $odd ? 'odd' : 'even';
$extraClass .= ' val' . str_replace(' ', '', $code);
- $itemID = $this->id() . '_' . ereg_replace('[^a-zA-Z0-9]+', '', $code);
+ $itemID = $this->id() . '_' . preg_replace('/[^a-zA-Z0-9]+/', '', $code);
$checked = $disabled = $inheritMessage = '';
$checked = (isset($uninheritedCodes[$code]) || isset($inheritedCodes[$code])) ? ' checked="checked"' : '';
$title = $permission['help'] ? 'title="' . htmlentities($permission['help'], ENT_COMPAT, 'UTF-8') . '" ' : '';
@@ -281,4 +281,4 @@ class PermissionCheckboxSetField_Readonly extends PermissionCheckboxSetField {
function saveInto($record) {
return false;
}
-}
+}
Please sign in to comment.
Something went wrong with that request. Please try again.