PHP - Moved: Ereg_replace To Preg_replace? ( Ereg Depricated )
This topic has been moved to PHP Regex.
http://www.phpfreaks.com/forums/index.php?topic=347016.0 Similar TutorialsI had this code but now I need to change it to newer preg_replace function Can someone help me to do it please? Here is the code: $newString = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]","<a href=\"\\0\" target=\"_blank\">\\0</a>", $originalString); Thanks in advance. $customer_contact_id = preg_replace("`", "", $customer_contact_id); Am I doing something wrong? Every page that used the eregi_function, I changed to have it utilize the preg_function (because I saw a Youtube video telling me to do so). Now, every variable I perform the above on acts as if it doesn't exist. This has totally destroyed my system. What do I need to do here to fix things? This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=307671.0 This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=320413.0 This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=358821.0 This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=350441.0 This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=332527.0 This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=347057.0 This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=359592.0 This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=306005.0 This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=346278.0 This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=330098.0 This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=320391.0 PLEASE HELP - PLEASE HELP HOW TO MAKE THIS RUN FOR PHP+
<?php
// This is our base class for publishing plugins!
class Publish {
function Publish ( $sql ) {
function getInfo () {
$details [ 'name' ] = $this->getName ();
return $details;
/* return an array containing all property data */
// firstly let's get the various info to make this job easier on MySQL<5
$status_data = $this->sql->execute (
for ( $i = 0; $i < sizeof ( $status_data ); ++$i ) $location = array ();
$loc_data = $this->sql->execute (
for ( $i = 0; $i < sizeof ( $loc_data ); ++$i ) $type = array ();
$type_data = $this->sql->execute (
for ( $i = 0; $i < sizeof ( $type_data ); ++$i )
// get all property data
// now go through and fill in the status, type and location data
for ( $f = 0; $f < sizeof ( $features ); ++$f )
$data [ $i ] [ 'propertytype_text' ] =
$data [ $i ] [ 'propertylocation_text' ] =
$data [ $i ] [ 'propertystatus_text' ] = $fulldata [ 'data' ] = $data;
$fields = array ( $fulldata [ 'fields' ] = $fields;
return $fulldata;
// these must be overridden
$data = $fulldata [ 'data' ];
header ( "Content-Type: text/tab-separated-values" ); $rows = array ();
for ( $i = 0; $i < sizeof ( $data ); ++$i )
foreach ( $fields as $field )
array_push ( $rows, implode ( "\t", $vals ) ); print implode ( "\n", $rows );
exit (); ?> This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=331361.0 This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=347065.0 It seems ereg is deprecated in php 5+ so what is a good alternative? Thanks! does anyone know why I am getting the error: Deprecated: Function ereg() is deprecated on line 75 ? here is line 75 (line 3, the seond if statement): if($form_cc_type == 'visa') { if(!ereg('^4[0-9]{12}([0-9]{3})?$', $form_cc_number)) { $form_error = "Invalid number"; } } I am assuming I would get a simular error on all the ereg lines... if($form_cc_type == 'visa') { if(!ereg('^4[0-9]{12}([0-9]{3})?$', $form_cc_number)) { $form_error = "Invalid number"; } } elseif($form_cc_type == 'mastercard') { if(!ereg('^5[1-5][0-9]{14}$', $form_cc_number)) { $form_error = "Invalid number"; } } elseif($form_cc_type == 'americanexpress') { if(!ereg('^3[47][0-9]{13}$', $form_cc_number)) { $form_error = "Invalid number"; } } elseif($form_cc_type == 'diners') { if(!ereg('^3(0[0-5]|[68][0-9])[0-9]{11}$', $form_cc_number)) { $form_error = "Invalid number"; } } elseif($form_cc_type == 'discover') { if(!ereg('^6011[0-9]{12}$', $form_cc_number)) { $form_error = "Invalid number"; } } I'm sure this issue has been addressed before, but as I can't find anything on google OR bing, I've resorted to asking it he Since, ereg and eregi are deprecated in PHP5, how do you test strings using regular expressions? Is there a new function for this? EDIT: I also looked on php.net, but all it says is its deprecated in PHP5. I didn't see any links to the new function(s) that have replaced the former. Hi: Is it possible to use the ereg() function in a file upload script so that the ereg() can recognize whether or not the file type is a .jpg, .gif, .png? I already figured out how to do it without using the ereg() function - but I'm just interested to know if it is possible using ereg()..if so, could you provide me with an example? I'm also a bit confused as to how to use ereg() to recognize file types. Here;s what I've done: Code: [Select] function getExtension($str) { $i = strrpos($str,"."); if (!$i) { return ""; } $l = strlen($str) - $i; $ext = substr($str,$i+1,$l); return $ext; } if ($image) { $filename = stripslashes($_FILES['image']['name']); $extension = getExtension($filename); $extension = strtolower($extension); if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif")) { echo '<h1>Unknown extension!</h1>'; $errors=1; } Thanks! |