|
-
Mar 1st, 2006, 08:23 PM
#1
Thread Starter
Frenzied Member
cant access vars within function?
PHP Code:
<?php
$a= $HTTP_GET_VARS['a'];
$b= $HTTP_GET_VARS['b'];
$c= $HTTP_GET_VARS['c'];
$d= $HTTP_GET_VARS['d'];
$e= $HTTP_GET_VARS['e'];
$f= $HTTP_GET_VARS['f'];
$g= $HTTP_GET_VARS['g'];
function writeout($msg){
$filename = "files/" . $a . "tmp.html";
$fh= fopen($filename, 'a') or die("can't open file");
if (filesize($filename) ==0) {
//add the top stylesheet
$SS = "files/css.txt";
$Style= fopen($SS, 'r') or die("can't open file");
$read = fread($Style, filesize($SS));
fwrite($fh, $read);
fclose($Style);
}
$b = str_replace("&","&",$b);
$c = str_replace("&","&",$c);
$a = str_replace("&","&",$a);
$d = str_replace("&","&",$d);
$e = str_replace("&","&",$e);
$f = str_replace("&","&",$f);
$g = str_replace("&","&",$g);
$newline = "\r\n";
fwrite($fh, $newline."<table border=2 width=" .chr(34)."5%".chr(34).">");
fwrite($fh,"<tr class=".chr(34)."hdr".chr(34).">");
fwrite($fh,"<td>".$a."</td>");
fwrite($fh, $newline."<a href="."http://www.site.com/".$msg." "."target=" .chr(34). "_blank".chr(34).">"."username"."</a></td>");
fwrite($fh,"<td></td></tr>");
fclose($fh);
}
writeout($a);
writeout($b);
writeout($c);
writeout($d);
writeout($e);
writeout($f);
writeout($g);
?>
giving me undefined variable a,b,c,d,e,f,g etc.. as if i dont have access to the vars within the fucntion?
-
Mar 1st, 2006, 08:50 PM
#2
<?="Moderator"?>
Re: cant access vars within function?
Try looking at global. This will allow you access variables from outside the function's scope.
-
Mar 1st, 2006, 09:23 PM
#3
Re: cant access vars within function?
Yes - without a global statement in your function, you are writing to different vars.
-
Mar 1st, 2006, 10:10 PM
#4
Thread Starter
Frenzied Member
Re: cant access vars within function?
good one.
Next:
If i have a string,
$strstring = "a=first;b=next;c=middle;d=next"
how would i extract middle, i know i have strstr()
so strstr($strstring,'c=') would give me middle;d=next
i need to do a double split?
-
Mar 1st, 2006, 10:14 PM
#5
Re: cant access vars within function?
Something like
PHP Code:
$vars = explode(';', $strstring);
echo trim(substr($vars[2], $start = strpos($vars[2], '='), strlen($vars[2]) - $start));
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|