In PHP, all vars are local to current context, unless decl. as 'global' inside
that context.
Can use globals in functions AND set them there: like static vars.
global ${$varname}; $currentval = ${$varname};
OR $currentval = $GLOBALS[$varname]);
Doesn't seem to matter if a func def. is after the first call to it.
Must use POST if big strings in data, else PHP seems to block them.
// SHOW EVERYTHING of what php server has/knows
//foreach ($GLOBALS as $key => $val) { echo "$key => $val "; };
//phpinfo();
UNIX CALLOUTS
**Simple
system(' ./wtable < calendar.tab 2>&1'); also works
**Solutions
$cmd = "wtable < $tab;";
system('(export PATH=.:/home/steve/bin:$PATH ;' . $cmd . ') 2>&1');
**Callouts:
exec('ls', &$mylist);
foreach ($mylist as $f) { echo "$f \n"; };
Can set PATH to have my programs work.
$cmd = "wtable < $tab;";
system('(export PATH=.:~steve/bin:/home/steve/bin:$PATH ;' . $cmd . ')
2>&1');
// ~steve doesn't seem to work now. But full path name does, or link
prog into local dir. where xx.php is.
system: &1') // echos it all out to webpage (LFs as sps)
?>
echo exec:
exec('ls -lt', &array):fills array, one line per entry.
shell_exec(cmd) returns output as a string.
system : &1 ') ?>
system('csh -c "chdir redir; perl uextract < History.html >> out" 2&1');
PROBLEMS
0) The biggest problem is poor error messages e.g.saying "cmd not found"
when really it's forbidding the exec of binaries not in original 2 bins.
1) Won't run binaries in local dir: says "no such file", even though it's there.
It isn't because it's the wrong processor binary.
2) Seem to have to refer to local scripts as ./file. (or redir/file is OK)
./script will work but script will not.
Fix: system('export PATH=.:$PATH ; q; 2>&1'); Works!
3) Will run local scripts.
And the #! /bin/csh -f works, even in sh; BUT the path given has to
work on the server m/c, not just mine/Lion.
4) Will follow symlinks BUT the target may not be there on the PHP server system
5) Any writing to files MUST have the files with W permission in advance for
everyone. /tmp OK.
DE-REFFING / INDIRECTION
echo $$name will output the value of the variable whose name is in $name.
echo ${'url' . 3} will output valof $url3. === $name = 'url' . 3; echo $$name;
$s = 'echo $url' . 3 .';'; eval($s);
I.E. you can do double de-reffing with $$;
The braces make it work even if tricky syntax/calc inline on the name,
and no 2nd $ in that case.
Could also use eval() if you prefer to construct a whole statement as a string
not just one varname.
EVAL
eval() executes a bit of code given as a string arg.
Includes decls ('global ...'); output ('echo ... ').
Must have semicolon at end of the statement-string.
ARRAYS
$ctable[$table[count($table)-1][0]] = 'witch2.jpg';
//$ctable[$table[end(array_keys($table))][0]] = 'witch2.jpg';
$arr1 = $arr0; makes a copy;
Not so easy to get last elem of array. end() sets ptr; pop*() removes not
copies last elem, ....
if (!is_array($ctable[$ckey])) { $ctable[$ckey] = array(); }
ANCHORS
Since anchors (#tag part of URL) are only needed in the browser, they may not
be sent to server?
However PHP par parse_url($url) will return it in ['fragment'] if it's there.
There is a workaround if you have to get the anchor to PHP server from browser:
Use javascript in page returned to client;
Have javascript set a cookie with the anchor in, from document.location which
is URL with anchor in.
Re-fresh page so cookie is sent to server.
[in plain html...]
[ and from here on, can access the anchor in php from the cookie var]
FOCUS ON TEXT FIELD ONlOAD()
The std. thing in many of my pages is to have the text box already with the
pointer: focus, highlighted, selected. That's good.
But if the page is also (sometimes) called with an #anchor, then instead of
scrolling to the textbox, it should allow the browser to scroll to the anchor.
So: should use this as std. in my pages, to get initial select/focus
function sf(){var x = location.href.split('#'); if (x && x.length>1) return;
document.myform.uservalue.focus(); document.myform.uservalue.select();}
<.. onLoad="sf()" ..>
NB1: call it not sf() but ReadyToType() or SetFocus() ?
NB2: do I still need both focus() and select() ?
NB3: referring to the right box isn't automated.
Am using document.form-name.ipbox-name
Form names seem to be directly in document regardless of DOM nesting.
FORMs can't be nested
Elements seem to be directly in FORM regardless of nesting.?
33: Could set an ID and do getElementById()
Could get all