-1

Hello, This is displayed my wordpress page. Every User can see it. How can I fix it?

For security, I replaced the actual directory with "..."

Notice: Undefined offset: 1 in /.../functions.php on line 163

Notice: Undefined offset: 1 in /.../functions.php on line 168

Notice: Undefined offset: 3 in /.../functions.php on line 169

Warning: Division by zero in /.../functions.php on line 172

This is my code in Functions.php:

function gal_add_new_height_width($embed){

    $no_prev_match = 0;
    preg_match('/width="(\d+)(px)?" height="(\d+)(px)?"/', $embed, $matches);

    if(!$matches[1]){
        $no_prev_match = 1;
        preg_match('/width: (\d+)px; height: (\d+)px"/', $embed, $matches);
    }

    $width = intval($matches[1]);
    $height = intval($matches[3]);

    $new_width = gal_width() * 3 + gal_gap() * 2;
    $new_height = intval($new_width * $height / $width);

    $embed = preg_replace('/width="(\d+)(px)?" height="(\d+)(px)?"/', 'width="' . $new_width . '" height="' . $new_height . '"', $embed); 
    $embed = preg_replace('%style=".*"%smUi',"",$embed);    
    return $embed;
}

Thanks in advance.

Elias
  • 23
  • 4
  • 1
    possible duplicate of [PHP: "Notice: Undefined variable" and "Notice: Undefined index"](http://stackoverflow.com/questions/4261133/php-notice-undefined-variable-and-notice-undefined-index) – CBroe Jan 07 '15 at 18:27
  • Your array (`$matches[]`) doesn't have items at the indexes you're looking for. Try printing the array first to see what you're actually matching in the `preg_match` – jnpdx Jan 07 '15 at 18:29

1 Answers1

0

Basically what is happening is that you are referencing array values that don't exist. It is trying to find a string match in the given input, and cannot find it. This could be due to a number of reasons, none of which any of us can likely solve for you.

In order to correctly solve the problem, you need to understand what this code is doing and why the input string does not contain the text it's looking for.

I hesitate, but as a temporary workaround, you can do something like:

function gal_add_new_height_width($embed){

    $no_prev_match = 0;
    if (preg_match('/width="(\d+)(px)?" height="(\d+)(px)?"/', $embed, $matches)) {

        if(!$matches[1]){
            $no_prev_match = 1;
            preg_match('/width: (\d+)px; height: (\d+)px"/', $embed, $matches);
        }

        $width = intval($matches[1]);
        $height = intval($matches[3]);

        $new_width = gal_width() * 3 + gal_gap() * 2;
        $new_height = intval($new_width * $height / $width);

        $embed = preg_replace('/width="(\d+)(px)?" height="(\d+)(px)?"/', 'width="' . $new_width . '" height="' . $new_height . '"', $embed); 
        $embed = preg_replace('%style=".*"%smUi',"",$embed);
    }    
    return $embed;
}

But note that this won't fix your problem. It will only make this function do nothing instead of error. So your wp site may be broken elsewhere until you fully understand why.

jrel
  • 187
  • 1
  • 11