我对编码很新,最近刚开始将功能集成到我的PHP中。我正在尝试对Google Analytics的IP地址进行编码和回显。这就是我的自定义修改器的样子:
pagetracker._setCustomVar(1, "IP", "<?php include function.php; echo remove_numbers_advanced($_SERVER['REMOTE_ADDR']); ?>", 2);
函数文件如下所示:
<?
function remove_numbers_advanced($string)
{
$numbers = array();
for($counter =0; $counter <= 10; $counter++) {
$numbers[$counter] = $counter;
$replacements = array("A","7","B","6","C","4","D","3","E","F");
$string = str_replace($numbers, $replacements, $string);
return $string;
}';
echo remove_numbers_advanced($string);
?>
当我将自定义变量的PHP部分隔离以试图测试它时,页面会抛出500错误,向我建议我的脚本设置有问题。
请记住,我对这个如此简单的术语和例子很新,这对我来说很有帮助!
答案 0 :(得分:1)
您的功能中存在少量错误。正确的功能是:
function remove_numbers_advanced($string)
{
$numbers = array();
for($counter =0; $counter <= 10; $counter++)
$numbers[$counter] = $counter;
$replacements = array("A","7","B","6","C","4","D","3","E","F");
$string = str_replace($numbers, $replacements, $string);
return $string;
}
1-您在for循环旁边添加了开放花括号但未关闭它
2-在功能的闭合括号中还有“';”。它不应该存在。
答案 1 :(得分:0)
include函数必须有一个字符串参数,所以把''放在文件名
pagetracker._setCustomVar(1, "IP", "<?php include 'function.php'; echo remove_numbers_advanced($_SERVER['REMOTE_ADDR']); ?>", 2);