Jump to content

PHP Deprecated: Function ereg_replace() is deprecated in


rastaman46

Recommended Posts

Hello got some problems with it if im change to "preg_replace its just stop working my php version is 5.3.10

 

Please help

 

$loop = array("AVERAGETIME", "CURRENTLISTENERS", "PEAKLISTENERS", "MAXLISTENERS", "SERVERGENRE", "SERVERURL", "SERVERTITLE", "SONGTITLE", "SONGURL", "IRC", "ICQ", "AIM", "WEBHITS", "STREAMHITS", "LISTEN", "STREAMSTATUS", "BITRATE", "CONTENT");
$y=0;
while($loop[$y]!=''){
  $pageed = ereg_replace(".*<$loop[$y]>", "", $page);
  $scphp = strtolower($loop[$y]);
  $$scphp = ereg_replace("</$loop[$y]>.*", "", $pageed);
// uncomment the next line to see all variables
//echo'$'.$scphp.' = '.$$scphp.'<br>';
  $y++;
}

Link to comment
Share on other sites

Perl Regex (preg) is different than POSIX Regex (ereg).

 

Add "/' to the beginning and end of your patterns (and a "g" modifier if you want to replace all), and escape ("\") special characters in your patterns - <> / ( ) [ ] etc.

 

That should get things working again, e.g.:

$pageed = preg_replace("/.*\<{$loop[$y]}\>/g", "", $page);

 

Link to comment
Share on other sites

Php doesn't have a g modifier for pcre functions.  preg_replace()  by default performs global search and replace, and if you want to limit it there's an optional argument to pass to it

 

Oops!  I stand corrected... Been working with too much JS lately, and completely forgot about that idiosyncrasy in php! :)

 

thanks for replay but if im use your exemple im get

 

Warning: preg_replace() [function.preg-replace]: Unknown modifier 'g' in

 

Per josh's comment, if you remove the "g" it should work:

 

$pageed = preg_replace("/.*\<{$loop[$y]}\>/", "", $page);

Link to comment
Share on other sites

before...

 

$pageed = ereg_replace(".*<$loop[$y]>", "", $page);

 

after:

 

$pageed = preg_replace("/.*\<{$loop[$y]}\>/", "", $page);

 

 

before...

 

$$scphp = ereg_replace("</$loop[$y]>.*", "", $pageed);

 

after:

 

??? 

 

 

You have two lines of code that have the same problem: using a deprecated function.  You have been told what you need to change, and someone even did the first line for you, so all you need to do is follow the instructions, or failing that, look at the changes in your first line and apply the same changes to the second line.  Exactly what part of this are you having trouble with?  Because at this point, this isn't even about coding, it's simple clerical skills...find and copy...

 

 

 

 

Link to comment
Share on other sites

Thanks for replay

 

after  $$scphp = preg_replace("\<{$loop[$y]}\>/.*", "", $pageed);

 

but get error "Delimiter must not be alphanumeric or backslash in"

 

 

 

Your first line of code has a / right after the opening ", and right before the closing ".  How...HOW did you translate that to using a backslash as the opening delimiter, and putting the closing delimiter somewhere before your pattern ends? Man, you are making this WAY harder than it needs to be....I'm being serious here, not mean..if this is seriously too hard for you to understand, then you need to find another hobby besides coding, because this is NOT coding, this is copy and paste.  If you cannot understand basic copy and paste, then you cannot even begin to code. 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.