1

Here is the small php example :

echo '<pre>';

// Execute httpd.exe -V to find apache version
exec('"E:\Program Files\AMPPS\apache\bin\httpd.exe" -V', $out, $ret);

// preg_replace_callback to fetch version
echo $apver = preg_replace_callback('/Server version: Apache\/(.*?) \((.*?)\)/is', function ($matches){ return $apache_version = trim($matches[1]); } ,$out[0]);
echo "\n";
echo "\n";

// Test this file with PHP 5.3
exec('"E:\Program Files\AMPPS\php\php.exe" -l "'.__FILE__.'"', $out1, $ret1);
print_r(array($out1, $ret1));

// Test this file with PHP 5.2
exec('"E:\Program Files\AMPPS\php-5.2\php.exe" -l "'.__FILE__.'"', $out2, $ret2);
print_r(array($out2, $ret2));

Output :

2.4.6

Array
(
    [0] => Array
        (
            [0] => No syntax errors detected in E:\Program Files\AMPPS\www\preg_replace.php
        )

    [1] => 0
)
Array
(
    [0] => Array
        (
            [0] => 
            [1] => Parse error: syntax error, unexpected T_FUNCTION in E:\Program Files\AMPPS\www\preg_replace.php on line 5
            [2] => Errors parsing E:\Program Files\AMPPS\www\preg_replace.php
        )

    [1] => -1
)

I need a syntax that will work in both PHP 5.2 and 5.3.

Thanks.

1 Answer 1

5

Closures definitions using function keyword is available only since PHP 5.3 Prior to 5.3 version you can use only create_function to define anonymous functions.

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

3 Comments

Done. I will create a callback function outside. And specify its name in the argument. Cannot accept answers so soon. Hehe.
Can you change your second link from /ru/ to /en/ please :)
oops. Proxy error, thanks. That's "smart google" substitutes external IP location language :p

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.