我是PHP编程的新手。 运行以下PHP代码生成URL时出现此错误。 我使用PHP 5.3.5。
(!)解析错误:语法错误,意外 T_CONSTANT_ENCAPSED_STRING,期待'&'或T_VARIABLE in 第30行的C:\ wamp \ www \ test \ urlgen.php
function bg_gen_secure_uri(
'http://demo.com/abc/secure/movie/movie-full-film_256x144-150.mp4',
'MqG9$fso2lt7(',
$expiry = 0,
$allowed_countries = '',
$disallowed_countries = '',
$allowed_ip = '',
$allowed_useragent = '',
$allowed_metros = '',
$disallowed_metros = '', $progressive_start = '', $progressive_end = '',
$extra_params = '' )
{
return $url;
}
如果我得到答案,我将非常感激。
答案 0 :(得分:1)
为什么要给两个常数作为参数?
'http://demo.com/abc/secure/movie/movie-full-film_256x144-150.mp4','MqG9$fso2lt7(',
那部分是错的。使用某些东西分配,可能是这样的:
<?php
function bg_gen_secure_uri($p1 = 'http://demo.com/abc/secure/movie/movie-full-film_256x144-150.mp4', $p2 = 'MqG9$fso2lt7(', $expiry = 0, $allowed_countries = '',$disallowed_countries = '', $allowed_ip = '', $allowed_useragent = '',
$allowed_metros = '',
$disallowed_metros = '', $progressive_start = '', $progressive_end = '',
$extra_params = '')
{
return $url;
}
?>
并且没有<php>
标记。删除它!
答案 1 :(得分:1)
您的函数参数必须是变量,对于默认值,您必须使用如下:
<?php
function bg_gen_secure_uri (
$ca='http://demo.com/abc/secure/movie/movie-full-film_256x144-150.mp4',
$b='MqG9$fso2lt7(',
$expiry = 0,
$allowed_countries = '',
$disallowed_countries = '',
$allowed_ip = '',
$allowed_useragent = '',
$allowed_metros = '',
$disallowed_metros = '',
$progressive_start = '',
$progressive_end = '',
$extra_params = ''
)
{
return $url;
}
echo bg_gen_secure_uri();
?>