致命错误:解析错误:语法错误,意外的 $end in [英] fatal error: Parse error: syntax error, unexpected $end in

查看:25
本文介绍了致命错误:解析错误:语法错误,意外的 $end in的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是在旧 PHP 版本上运行良好的 wordpress 插件,但现在在 PHP5.4.X 上产生以下错误.

无法激活插件,因为它触发了致命错误.

解析错误:语法错误,意外的 $end in C:\wamp\www\testweb\wp-content\plugins\bxslider\slider.php 第 175 行

这里是 SLIDER.PHP 文件.

get_results($query);if($_GET['mode']=='edit'){$query="select * from wp_slider where id='".$_GET['id']."'";$cur_slider_res=$wpdb->get_results($query);}include_once 目录名(__FILE__).'/options_page.php';}函数 bx_settings_update(){全球 $wpdb;if(isset($_POST['total_options'])){echo '<div class="更新淡入淡出" id="message"><p>内容幻灯片设置<strong>更新</strong></p></div>';for($i=1;$i<=($_POST['total_options']-1);$i++){if(!empty($_POST['wpcs_options']['slide_imagetext'.$i])){$query="INSERT INTO `wp_slider` (`image`, `link`, `content`,`name`) VALUES ('".$_POST['wpcs_options']['slide_image'.$i]."','".$_POST['wpcs_options']['slide_imagelink'.$i]."', '".$_POST['wpcs_options']['slide_imagetext'.$i]."', '".$_POST['姓名']."');";$wpdb->查询($查询);}}//update_option('bx_options', $_POST['bx_options']);}if($_GET['mode']=='delete'){$wpdb->query("Delete from wp_slider where id='".$_GET['id']."'");header("位置:admin.php?page=bxslider/slider.php");}if($_GET['mode']=='edit' && isset($_POST['id'])){$wpdb->query("更新 wp_slider set image='".$_POST['wpcs_options']['slide_image1']."', link='".$_POST['wpcs_options']['slide_imagelink1']."', content='".$_POST['wpcs_options']['slide_imagetext1'] ."',name='".$_POST['name'] ."' where id='".$_POST['id']."'");header("位置:admin.php?page=bxslider/slider.php");}}函数创建表(){全球 $wpdb;$qndTable = $wpdb->prefix ."滑块";if($wpdb->get_var("show tables like '$qndTable'") != $qndTable){$create = "创建表".$qndTable ." (`id` int(11) NOT NULL AUTO_INCREMENT,`image` varchar(255) 非空,`link` varchar(255) 非空,`content` 文本不为空,`name` varchar(255) 非空,主键(`id`)) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;";require_once(ABSPATH .'wp-admin/includes/upgrade.php');dbDelta($create);}}函数删除表(){全球 $wpdb;$wpdb->query("DROP table ".$wpdb->prefix ."slider");}register_activation_hook(__FILE__, 'createTable');register_deactivation_hook(__FILE__, 'deleteTable');功能 bxcontent_slider( $atts ) {$sname=$atts[滑块];$type=$atts[类型];if(!$type) $type='image';全球 $wpdb;$query="Select * from wp_slider where name='".$sname."' ";$slider_res=$wpdb->get_results($query);addbx_head($sname);if($type=='图像'){$content .='
    ';foreach($slider_res 作为 $slider){$content .= '<li><img src="'.$slider->image.'"/></li>';}$content .='</ul>';}elseif($type=='内容'){$content .='<div class="'.$sname.'">';foreach($slider_res 作为 $slider){$content .= '

    '.$slider->content.'

    ';}$content .='</div>';}返回 $content;//echo "slider = {$atts[slider]}";}add_shortcode('bxcontentslider', 'bxcontent_slider');函数 addbx_head($sname){?><脚本语言='javascript'>var $jquery = jQuery.noConflict();$jquery(document).ready(function(){$jquery('.<?php echo $sname ?>').bxSlider({自动:真,控制:假,pagerCustom: '#bx-pager-<?php echo $sname?>',pagerActiveClass:"活动"});});<?}函数 add_bxjs() {/*wp_enqueue_script('自定义脚本',plugins_url('/bxslider/jquery.bxslider.js', __FILE__ ) ,数组('jquery'));*/wp_enqueue_style('bxstyle', plugins_url('/bxslider/jquery.bxslider.css', __FILE__ ));wp_enqueue_script('jquery',plugins_url('/bxslider/jquery.min.js', __FILE__ ), array('jquery'));wp_enqueue_script('easing',plugins_url('/bxslider/jquery.easing.1.3.js', __FILE__ ), array('jquery'));wp_enqueue_script('bxscript',plugins_url('/bxslider/jquery.bxslider.js', __FILE__ ), array('jquery'));}add_action('wp_enqueue_scripts', 'add_bxjs');

第 175 行声明有 add_action('wp_enqueue_scripts', 'add_bxjs');

解决方案

您的 php 默认标签和短标签有问题.

<代码>PHP短标签<?php ... ?>PHP 默认标签

请参阅此处了解更多详情

请用以下代码替换最后几行

This is the wordpress plugin that was runing fine on old PHP version but now on PHP5.4.X producing the following error.

Plugin could not be activated because it triggered a fatal error.

Parse error: syntax error, unexpected $end in C:\wamp\www\testweb\wp-content\plugins\bxslider\slider.php on line 175

HERE is the SLIDER.PHP File.

<?php
error_reporting(1);
if(!defined('ABSPATH')) {
    die("Don't call this file directly.");
}
if (!defined('WP_CONTENT_URL')) {
    define('WP_CONTENT_URL', get_option('siteurl').'/wp-content');
}
define('CONTENT_SLIDE_URL',get_option('siteurl').'/wp-content/plugins/bxslider/');



/* Add Administrator Menu's*/
function bx_content_slide_menu()
{
    $level = 'level_10';
   add_menu_page('BX Content Slide', 'BX Content Slide', $level, __FILE__,'bx_content_slide_options',CONTENT_SLIDE_URL.'images/icon6.png');
   add_submenu_page(__FILE__, 'Help &amp; Support', 'Help &amp; Support', $level,'bx_content_slide_help','bx_content_slide_help');
}
add_action('admin_menu', 'bx_content_slide_menu');

function bx_content_slide_options()
{
    bx_settings_update();
    global $wpdb;
    $query="Select * from wp_slider";
    $slider_res=$wpdb->get_results($query);

    if($_GET['mode']=='edit'){
        $query="select * from wp_slider where id='".$_GET['id']."'";
        $cur_slider_res=$wpdb->get_results($query);


    }

    include_once dirname(__FILE__).'/options_page.php';
}


function bx_settings_update(){
    global $wpdb;
    if(isset($_POST['total_options']))
    {
        echo '<div class="updated fade" id="message"><p>Content Slide Settings <strong>Updated</strong></p></div>';


        for($i=1;$i<=($_POST['total_options']-1);$i++){
            if(!empty($_POST['wpcs_options']['slide_imagetext'.$i])){   
        $query="INSERT INTO `wp_slider` (`image`, `link`, `content`,`name`) VALUES ('".$_POST['wpcs_options']['slide_image'.$i]."', '".$_POST['wpcs_options']['slide_imagelink'.$i]."', '".$_POST['wpcs_options']['slide_imagetext'.$i]."', '".$_POST['name']."');";
        $wpdb->query($query);
            }
        }
        //update_option('bx_options', $_POST['bx_options']);
    }
    if($_GET['mode']=='delete'){
        $wpdb->query("Delete from wp_slider where id='".$_GET['id']."'");
        header("location:admin.php?page=bxslider/slider.php" );
    }
    if($_GET['mode']=='edit' && isset($_POST['id'])){

    $wpdb->query("update wp_slider set image='".$_POST['wpcs_options']['slide_image1']."', link='".$_POST['wpcs_options']['slide_imagelink1']."', content='".$_POST['wpcs_options']['slide_imagetext1'] ."',name='".$_POST['name']  ."' where id='".$_POST['id']."'");
        header("location:admin.php?page=bxslider/slider.php" ); 

    }


}


function createTable()
{
      global $wpdb;

    $qndTable = $wpdb->prefix . "slider";

    if($wpdb->get_var("show tables like '$qndTable'") != $qndTable)
    {
        $create =   "CREATE TABLE " . $qndTable . " (
                              `id` int(11) NOT NULL AUTO_INCREMENT,
                              `image` varchar(255) NOT NULL,
                              `link` varchar(255) NOT NULL,
                              `content` text NOT NULL,
                              `name` varchar(255) NOT NULL,
                              PRIMARY KEY (`id`)
                            ) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;";

        require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
        dbDelta($create);

    }
}
function deleteTable(){
     global $wpdb;
     $wpdb->query("DROP table ".$wpdb->prefix . "slider");

}

register_activation_hook(__FILE__,  'createTable');

register_deactivation_hook(__FILE__,  'deleteTable');


function bxcontent_slider( $atts ) {
    $sname=$atts[slider];
    $type=$atts[type];
    if(!$type) $type='image';
    global $wpdb;
    $query="Select * from wp_slider where name='".$sname."' ";
    $slider_res=$wpdb->get_results($query);


    addbx_head($sname);         

    if($type=='image'){
    $content .='<ul class="'.$sname.'">';   
        foreach($slider_res as $slider){
            $content .= '<li><img src="'.$slider->image.'" /></li>';
        }
    $content .='</ul>';
    }elseif($type=='content'){
    $content .='<div class="'.$sname.'">';  
        foreach($slider_res as $slider){
        $content .= '<div>'.$slider->content.'</div>';
        }
        $content .='</div>';
    }

    return $content;
    // echo  "slider = {$atts[slider]}";
}
add_shortcode('bxcontentslider', 'bxcontent_slider');
function addbx_head($sname){
?>
<script language='javascript'>
                var $jquery = jQuery.noConflict(); 
                $jquery(document).ready(function(){

                  $jquery('.<?php echo $sname ?>').bxSlider({
                      auto:true,
                      controls:false,
                       pagerCustom: '#bx-pager-<?php echo $sname?>',
                       pagerActiveClass:"active"
                      });


                });

                </script>
<?
}
function add_bxjs() {
    /*wp_enqueue_script(
        'custom-script',
        plugins_url('/bxslider/jquery.bxslider.js', __FILE__ ) ,
        array( 'jquery' )
    );*/
    wp_enqueue_style('bxstyle', plugins_url('/bxslider/jquery.bxslider.css', __FILE__ ));
    wp_enqueue_script('jquery',plugins_url('/bxslider/jquery.min.js', __FILE__ ), array('jquery'));
    wp_enqueue_script('easing',plugins_url('/bxslider/jquery.easing.1.3.js', __FILE__ ), array('jquery'));
    wp_enqueue_script('bxscript',plugins_url('/bxslider/jquery.bxslider.js', __FILE__ ), array('jquery'));
}

add_action( 'wp_enqueue_scripts', 'add_bxjs' );

The line 175 stated is have add_action( 'wp_enqueue_scripts', 'add_bxjs' );

解决方案

You have issue with php default and short tags.

<? ... ?>   PHP short tag
<?php ... ?> PHP default tag

See here for more details

Please replace your last few lines with following code

<?php
}
function add_bxjs() {
    /*wp_enqueue_script(
        'custom-script',
        plugins_url('/bxslider/jquery.bxslider.js', __FILE__ ) ,
        array( 'jquery' )
    );*/
    wp_enqueue_style('bxstyle', plugins_url('/bxslider/jquery.bxslider.css', __FILE__ ));
    wp_enqueue_script('jquery',plugins_url('/bxslider/jquery.min.js', __FILE__ ), array('jquery'));
    wp_enqueue_script('easing',plugins_url('/bxslider/jquery.easing.1.3.js', __FILE__ ), array('jquery'));
    wp_enqueue_script('bxscript',plugins_url('/bxslider/jquery.bxslider.js', __FILE__ ), array('jquery'));
}

add_action( 'wp_enqueue_scripts', 'add_bxjs' );
?>

这篇关于致命错误:解析错误:语法错误,意外的 $end in的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆