duan7264
duan7264
2015-04-27 10:20

如何修复“警告非法字符串”?

  • string
  • php
  • wordpress
已采纳

I was working on another PHP version. But when i upload the site to client server due to Different PHP version i am getting these errors

Warning: Illegal string offset 'name' in /homepages/3/d227794433/htdocs/flyefg/wp-content/plugins/gameplan-shortcodes/shortcodes/testimonial.php on line 53

Warning: Illegal string offset 'position' in /homepages/3/d227794433/htdocs/flyefg/wp-content/plugins/gameplan-shortcodes/shortcodes/testimonial.php on line 53

Warning: Illegal string offset 'company' in /homepages/3/d227794433/htdocs/flyefg/wp-content/plugins/gameplan-shortcodes/shortcodes/testimonial.php on line 53

Warning: Illegal string offset 'name' in /homepages/3/d227794433/htdocs/flyefg/wp-content/plugins/gameplan-shortcodes/shortcodes/testimonial.php on line 53

Warning: Illegal string offset 'position' in /homepages/3/d227794433/htdocs/flyefg/wp-content/plugins/gameplan-shortcodes/shortcodes/testimonial.php on line 53

Warning: Illegal string offset 'company' in /homepages/3/d227794433/htdocs/flyefg/wp-content/plugins/gameplan-shortcodes/shortcodes/testimonial.php on line 53

Warning: Illegal string offset 'name' in /homepages/3/d227794433/htdocs/flyefg/wp-content/plugins/gameplan-shortcodes/shortcodes/testimonial.php on line 53

Warning: Illegal string offset 'position' in /homepages/3/d227794433/htdocs/flyefg/wp-content/plugins/gameplan-shortcodes/shortcodes/testimonial.php on line 53

Warning: Illegal string offset 'company' in /homepages/3/d227794433/htdocs/flyefg/wp-content/plugins/gameplan-shortcodes/shortcodes/testimonial.php on line 53

Code on Line 53 is

$output .= '<div class="name">'.$atts['name'].($atts['position']?', '.$atts['position']:'').($atts['company']?' - '.$atts['company']:'').'</div>';

Whole code is (Line 35-62)

function parse_testimonial_item($atts, $content, $id){
    $position = isset($atts['position']) ? $atts['position'] : '';
    $name = isset($atts['name']) ? $atts['name'] : '';
    $company = isset($atts['company']) ? $atts['company'] : '';
    wp_enqueue_script( 'jquery-isotope');
    global $testimonial_slides;

    $output = '';
    if($testimonial_slides > 1){
        if(function_exists( 'head_slide' )){
            $output .= head_slide($testimonial_slides, '', '', array('page'=>true));
        }
    }
    $output .= '<div class="testimonial style-1">';
    $output .= '<div class="tt-content icon-quote-right">';
    $output .= strip_tags($content);
    $output .= '<div class="tt-tooltip"><!----></div>';
    $output .= '</div>';
    $output .= '<div class="name">'.$atts['name'].($atts['position']?', '.$atts['position']:'').($atts['company']?' - '.$atts['company']:'').'</div>';
    $output .= '</div>';
    if($testimonial_slides > 1){
        if(function_exists( 'footer_slide' )){
            $output .= footer_slide(array('page'=>true));
        }
    }
    return $output;

}

Thank you

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

3条回答

  • dongzhao1930 dongzhao1930 6年前

    the array variable $atts does not contain 'name,position' etc thats why you are getting this error. check the data that is coming in the array $atts. Just replace $atts with @$atts problem solved.

    点赞 评论 复制链接分享
  • doumie6223 doumie6223 6年前

    The problem with your code is that although you filtered the values in $atts, you're not re-using those variables.

    Your code should look like this :

    $output .= '<div class="name">'.$name.($position?', '.$position:'').($company?' - '.$company:'').'</div>';
    

    Instead of this :

    $output .= '<div class="name">'.$atts['name'].($atts['position']?', '.$atts['position']:'').($atts['company']?' - '.$atts['company']:'').'</div>';
    
    点赞 评论 复制链接分享
  • douwen1213 douwen1213 6年前

    At the very start of your function, you are checking if these values exist:

    $position = isset($atts['position']) ? $atts['position'] : '';
    $name = isset($atts['name']) ? $atts['name'] : '';
    $company = isset($atts['company']) ? $atts['company'] : '';
    

    So instead of using $atts[...] later on in your code, you should use the variables you have just set.

    Also note that you can get rid of the ternary expressions later on if you set the values correctly right away:

    $name = isset($atts['name']) ? $atts['name'] : '';
    $position = isset($atts['position']) ? (', ' . $atts['position']) : '';
    $company = isset($atts['company']) ? (' - ' . $atts['company']) : '';
    
    ...
    
    $output .= '<div class="name">'.$name.$position.company.'</div>';
    
    点赞 评论 复制链接分享