2

I am trying ti get value from javascript

$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];

I need value between tabSpecifications and Specifications

But i am getting error Notice: Undefined offset: 0 please help

1
  • Can you add the error you're seeing to your question? Commented Aug 1, 2015 at 16:41

1 Answer 1

1

I suppose that you just need /tabSpecifications.*?Specifications/ to match the string in this case.

Update:

Sorry, it's been a long time for me not writing PHP codes.

Something went wrong because dot matches all characters including spaces, but not \n, and we should use [\\s\\S] to match all the characters including \n or simply add sim to the regular expression.

<!-- 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]);
}

?>

References:

Sign up to request clarification or add additional context in comments.

1 Comment

@ipluse26 its also not working same error Notice: Undefined offset: 0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.