PHP preg_match从javascript获取值
我正在尝试从javascript获取值PHP preg_match从javascript获取值,javascript,php,preg-match,Javascript,Php,Preg Match,我正在尝试从javascript获取值 $tt = '<script type="text/javascript">tabCls.push( new pageModelTab( "tabSpecifications" , "/cusa/includeFile.action?productOverviewCid=0901e02480f8c511&componentCid=0901e024800bef11&userSelectedModel=0901e02480f8c51
$tt = '<script type="text/javascript">tabCls.push(
new pageModelTab(
"tabSpecifications"
, "/cusa/includeFile.action?productOverviewCid=0901e02480f8c511&componentCid=0901e024800bef11&userSelectedModel=0901e02480f8c511"
, "Specifications"
, 7
, false
, ""
, null
, true
, null
)
);
function onClick_tabSpecifications() {
try {
var location = new String(window.location);
if (location && location.indexOf("?selectedName") != -1) {
return true;
}
new TabState("7").addTabToBrowserHistory();
show("7");
showHideFooterDisclaimer(\'Specifications\');
return false;
} catch (e) {
//alert(e.message);
return true;
}
}
</script>';
function matchin($input, $start, $end){
$in = array('/');
$out = array('\/');
$startCh = str_replace($in,$out, $start);
$endCh = str_replace($in,$out, $end);
preg_match('/(?<='.$startCh.').*?(?='.$endCh.')/', $input, $result);
return array($result[0]);
}
$matchin = matchin($tt,'tabSpecifications','Specifications');
echo $matchin[0];
$tt='tabCls.push(
新页面模型选项卡(
“标签规格”
,“/cusa/includeFile.action?产品概述CID=0901e02480f8c511和组件CID=0901e024800bef11和用户选择的模型=0901e02480f8c511”
,“规格”
7.
,错
, ""
无效的
是的
无效的
)
);
函数onClick_tabSpecifications(){
试一试{
变量位置=新字符串(window.location);
if(location&&location.indexOf(“?selectedName”)!=-1){
返回true;
}
新TabState(“7”).addTabToBrowserHistory();
显示(“7”);
showHideFooterDisclaimer(\'Specifications\');
返回false;
}捕获(e){
//警报(e.message);
返回true;
}
}
';
函数匹配($input、$start、$end){
$in=数组('/');
$out=数组('\/');
$startCh=str_replace($in,$out,$start);
$endCh=str_replace($in,$out,$end);
preg_match('/(?我想您只需要/tabSpecifications.*?Specifications/
来匹配本例中的字符串
更新:
对不起,我很久没写PHP代码了
出现了一些问题,因为点匹配所有字符,包括空格,但不匹配\n
,我们应该使用[\\s\\s]
匹配所有字符,包括\n
或简单地将sim
添加到正则表达式中
<!-- language: lang-php -->
<?php
function matchin($input, $start, $end){
$in = array('/');
$out = array('\/');
$startCh = str_replace($in, $out, $start);
$endCh = str_replace($in, $out, $end);
$pattern = '/(?<='.$startCh.').*?(?='.$endCh.')/sim';
// or you can use
// $pattern = '/(?<='.$startCh.')[\\s\\S]*?(?='.$endCh.')/';
preg_match_all($pattern, $input, $result);
return array($result[0]);
}
?>
参考资料:
您能将看到的错误添加到您的问题中吗?@ipluse26它也不起作用相同的错误注意:未定义的偏移量:0