PHP循环通过脚本数组&删除项目

php loop through scripts array & remove item

本文关键字:数组 删除项目 脚本 循环 PHP      更新时间:2023-09-26

我有以下脚本在我的cms页面:

window.addEvent('domready', function () {
    SqueezeBox.initialize({});
    SqueezeBox.assign($$('a.modal'), {
        parse: 'rel'
    });
});
var j2storeURL = 'http://tours-international.com.gridhosted.co.uk/';
if (typeof (J2Store) == 'undefined') {
    var J2Store = jQuery.noConflict();
}

J2Store(document).ready(function () {
    J2Store('.j2storeCartForm').each(function () {
        J2Store(this).validate({
            errorElement: 'em',
            errorPlacement: function (error, element) {
                error.appendTo(element.parent().parent().next('div'));
            },
            success: function (label) {
                //label.text('Ok').addClass('success');
            },
            submitHandler: function (form) {
                j2storeAddToCart('addtocart', form);
            }
        });
    });
});
jQuery(document).ready(function () {
    jQuery('.hasTooltip').tooltip({});
});

我想循环遍历上面的代码并删除以下JS:

SqueezeBox.initialize({});
SqueezeBox.assign($$('a.modal'), {
    parse: 'rel'
});

请给出最简单的方法

如果我正确理解了这个问题,您想从文件中删除该部分吗??

如果是,那么您可以执行以下操作:

  1. 将文件读入字符串$file_str = file_get_contents('your_file_path');
  2. 获取位置:$pos_a = strpos($file_str, "SqueezeBox")$pos_b = strpos($file_str, "var")
  3. 写回:substr_replace($file_str, "", $pos_a, ($pos_b - $pos_a));
好运