PHP preg_replace_callback help needed

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • acctman
    Confirmed User
    • Oct 2003
    • 2840

    #1

    PHP preg_replace_callback help needed

    trying to avoid going on stackoverflow don't want to deal with the Q&A ego police that mod that site. Any i'm getting this error Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in any assistance greatly appreciated

    Code:
    //load current language
            foreach ($langs as $key => $value) if ($value['l_code'] == lang) break;
            $f = fopen('languages/'.$langs[$key]['l_file'],'r') or die('Cannot open language file '.$langs[$key]['l_file']);
            while (!feof($f)) {
                    $s = chop(fgets($f,4096));
                    if ($s{0} == '#') continue;
                    list($key,$value) = explode('=',$s,2);
                    $value = preg_replace('/<%(.*)%>/sUe', '@constant("\\1")', $value);
                    $def[$key] = $value;
                    }
            fclose($f);
  • sarettah
    see you later, I'm gone
    • Oct 2002
    • 14297

    #2
    I don't deal with preg_replace that often but after spending a couple of minutes looking at preg_replace_callbak I am thinking that something like this will work:

    $value = preg_replace_callback('/<%(.*)%>/sU', function(){ return @constant("\\1"); }, $value);

    Worst that can happen is it won't ;p

    edited in: also remove the e modifier I think. I forgot to do that originally.

    .
    All cookies cleared!

    Comment

    • acctman
      Confirmed User
      • Oct 2003
      • 2840

      #3
      Originally posted by sarettah
      I don't deal with preg_replace that often but after spending a couple of minutes looking at preg_replace_callbak I am thinking that something like this will work:

      $value = preg_replace_callback('/<%(.*)%>/sU', function(){ return @constant("\\1"); }, $value);

      Worst that can happen is it won't ;p

      edited in: also remove the e modifier I think. I forgot to do that originally.

      .
      thanks that worked

      Comment

      • sarettah
        see you later, I'm gone
        • Oct 2002
        • 14297

        #4
        Originally posted by acctman
        thanks that worked
        Cool.

        .
        All cookies cleared!

        Comment

        Working...