1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

(2) preg_replace_callback(): Requires argument 2

Discussion in 'PHP' started by gregdavidson, Mar 7, 2017.

  1. #1
    Hi,

    I'm getting this error:

    (2) preg_replace_callback(): Requires argument 2, '', to be a valid callback

    Here's the line where the problem is:

    $file_contents = preg_replace_callback("!{$ldq}\*.*?\*{$rdq}!se","",$file_contents);

    I think it has something to do with an upgrade in the PHP. How do I correct this problem? Any help would be greatly appreciated.
     
    Solved! View solution.
    gregdavidson, Mar 7, 2017 IP
  2. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #2
    PoPSiCLe, Mar 7, 2017 IP
  3. gregdavidson

    gregdavidson Well-Known Member

    Messages:
    2,448
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    160
    #3
    gregdavidson, Mar 7, 2017 IP
  4. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #4
    Well, if you just want the original script to work, you can try changing preg_replace_callback with just preg_replace?

    Try this:
    
    $file_contents = preg_replace("!{$ldq}\*.*?\*{$rdq}!se","",$file_contents);
    
    Code (markup):
     
    PoPSiCLe, Mar 8, 2017 IP
  5. gregdavidson

    gregdavidson Well-Known Member

    Messages:
    2,448
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    160
    #5
    I get this error when I change it back to how it originally was.

    (8192) preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead
     
    gregdavidson, Mar 8, 2017 IP
  6. gregdavidson

    gregdavidson Well-Known Member

    Messages:
    2,448
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    160
    #6
    Last edited: Mar 8, 2017
    gregdavidson, Mar 8, 2017 IP
  7. yedort

    yedort Member

    Messages:
    23
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    33
    #7
    The second parameter of the preg_replace_callback has to be a function that'll accept one parameter and return the processed value.

    More visually:

    function mycallbackfunc($text){
    // Do something with $text
    // Then return your value
    }
     
    yedort, Mar 8, 2017 IP
  8. #8
    If you need to do it quickly, use this (I removed the e options):

    
    $file_contents = preg_replace("!{$ldq}\*.*?\*{$rdq}!s","",$file_contents);
    
    Code (markup):
     
    cesarpa, Mar 8, 2017 IP
    gregdavidson likes this.
  9. gregdavidson

    gregdavidson Well-Known Member

    Messages:
    2,448
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    160
    #9
    Thanks! That actually worked.
     
    gregdavidson, Mar 8, 2017 IP
  10. Larsad

    Larsad Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #10
    Hi,

    When i click on "Solved! View solution." in the first post, i have an error message :
    Digital Point - Error
    You do not have permission to view this page or perform this action.

    Thanks for any help
    :)
     
    Larsad, Aug 2, 2017 IP
  11. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #11
    Yep, that actually happens here also.
     
    PoPSiCLe, Aug 2, 2017 IP
  12. Larsad

    Larsad Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #12
    Thanks
     
    Larsad, Aug 3, 2017 IP