Newbe PHP: I'm haveing trouble running simple example code

I'm trying to get some PHP example code to work on PHP version 5.3.4, Apache 2.2.17 on Windows.

The example says I need PHP 4.0 and above with CURL and contains:

<? 
$function = $_GET['function-if-exist'];
$test = "Test";
?>

<? =$test ?>

I don't understand why I'm getting the following errors:

  • My PHP doesn't understand <? and wants <?PHP instead.
  • My PHP doesn't like <? =$test ?> and wants something like <?PHP echo $test ?>
  • $function = $_GET['function-if-exist']; causes the error "Undefined index" but presumably works for the folks that developed it.
  • Can anyone help me understand why their code is not working for me?


    1) <? is the "short tag". Most servers are configured to not allow short tags. This can be changed in php.ini .

    2) Again, short tags. Also I think you can't have a space before the = , but the main problem is the short tags setting.

    3) $_GET accesses the query string, so when loading your script you need myscript.php?function-if-exist=something


    在继续防止错误被抛出之前检查参数是否被设置是比较理想的,例如

    if(isset($_GET['function-if-exist']))
    {
        $functionexists = $_GET['function-if-exist'];
    }
    

  • the short tag notation is disabled in your php.ini
  • you need to remove the space before your equal sign
  • your _get array contains not the expected index, what url do you enter to access the page?
  • 链接地址: http://www.djcxy.com/p/9904.html

    上一篇: 使用R的零零假设

    下一篇: Newbe PHP:我在运行简单的示例代码时遇到了麻烦