LMPX.COM |
Home | Linux | Mysql | PHP | XML | ||
|
|
|||
From: Nathan Wallace Date: Tue Aug 10 12:19:15 1999 Subject: PHP Knowledge Base Update -- August 9th, 1999
The PHP development group today announced the second public Beta of PHP
4.0. This release features a significant amount of bug fixes, and is a
big step towards making PHP 4.0 a stable development platform. In
addition to bug fixes in the language engine itself, many modules have
been checked and updated to be PHP 4.0 compatible, so the number of
scripts that will successfully execute is significantly larger than that
of Beta 1. Finally, the Apache .conf/.htaccess conversion scripts
supplied with Beta 1 have been fixed and improved, so the transition
from PHP 3.x should be smoother. You can download it at:
http://www.php.net/version4/
I'm leaving (Australia) on a trip to the US and Canada next Monday. The
PHPKB summaries will be a little erratic from then until the end of
September. If you've got some time, good php knowledge, copy and paste
skills and you're willing to help let me know...
<shameless type="outreach">
One of the main reasons for the trip is so I can scope out work
opportunities. I'll be visiting SF, Boston, Ottawa, NY and LA. Send me
mail if you think we could help each other out.
I'll be attending the O'Reilly Open Source Software Convention
<http://conferences.oreilly.com> while I'm there. Mail me if you want
to meet up. (Or if you can help me get from Monterey to SF Airport on
the night of the 24th ;)
</shameless>
Sorry for the off topic trip chat,
Nathan
------------------------------------------------------------
How can I translate a date into another language?
http://e-gineer.com/e-gineer/phpkb/view.phtml/qid/560
------------------------------------------------------------
Mark Maggelet, sklar@student.net
Are you running on a system with locale support? If so, you can use
setlocale() and strftime() for this. On my Linux box, the PHP
<?php
setlocale('LC_TIME','en_US');
print strftime('%A, %B %d').'<P>';
setlocale('LC_TIME','fr_FR');
print strftime('%A, %B %d');
?>
produces:
Monday, August 09
lundi, aout 09
If you don't have locale support then you could just modify this
function to suit your needs:
function month_to_int($mon) {
$months = array('Jan'=>'01', 'Feb'=>'02', 'Mar'=>'03',
'Apr'=>'04', 'May'=>'05', 'Jun'=>'06',
'Jul'=>'07', 'Aug'=>'08', 'Sep'=>'09',
'Oct'=>'10', 'Nov'=>'11', 'Dec'=>'12');
return($months[$mon]);
}
you can switch the order ('01=>'Jan',...) to get int_to_month and put
whatever values you want for month names and do something similar for
week I guess.
------------------------------------------------------------
How can I get a string of words from a form into an array?
Should I use explode() or split() to separate a string of words?
http://e-gineer.com/e-gineer/phpkb/view.phtml/qid/561
------------------------------------------------------------
Jason Brooke
If you know that there will only be single spaces between the words then
you can use explode
$stuff = explode(" ",$field);
http://www.php.net/manual/function.explode.php3
If you are getting the string from a form or it might contain extra
spaces then you probably should use split which will match regular
expressions:
$stuff = split(" +",$field);
http://www.php.net/manual/function.split.php3
------------------------------------------------------------
How can I write the resulting HTML from a PHP script to a file?
http://e-gineer.com/e-gineer/phpkb/view.phtml/qid/563
------------------------------------------------------------
Shantonu Sen, Robert Aden, gigandet@eurecom.fr
Try the following script which writes the result of a second PHP script
to a file.
<?php
$filename = "http://servername/admin_prob.php3?id=2";
$filename2 = "/tmp/zzz.html";
$fd = fopen( $filename, "r" );
$fd2 = fopen($filename2, "w");
while (!feof($fd)) {
$line = fgets($fd, 1024);
fputs($fd2,$line);
}
fclose($fd);
fclose($fd2);
?>
Alternatively if you're just trying to get the output to a file, and
you're using unix, you can try using lynx and the -source flag:
lynx -source http://domain.com/path/test.php3?variable=3 >temp.html
the url might need quotes. you can set up a script to sequentially pass
all the variables.
------------------------------------------------------------
Will PHP return an error if I have a call to an undefined function but
that code branch is not run?
http://e-gineer.com/e-gineer/phpkb/view.phtml/qid/564
------------------------------------------------------------
prgr@u5.com
In good old compiled languages like C++ you are not allowed to do that.
I would think that it is an approach to be disrecommended - such things
are not a part of the language definition (I assume) so even if it works
now - the PHP-developer team might change it without notice, especially
if they later were to make a "compiler" for php3.
But - why not just write an empty function now and replace it later if
you need? Your code would work just the same - and you are on the safe
side! You can always use 'require' and 'include' to control which files
containing functions that are loaded.
------------------------------------------------------------
How can I setup PHP with Netscape Enterprise Server?
http://e-gineer.com/e-gineer/phpkb/view.phtml/qid/565
------------------------------------------------------------
First, take a look at
http://www.webgenx.com/Kwazy/phpunix.html
The obj.conf of a Netscape Enterprise 3.0 server is missing an entry to
handle the content-type magnus-internal/cgi for the Default
object. That content type is just exactly what the kwazy plugin
generates.
It is only logical that such an entry must be present in the default
object, though. We want to be able to execute php3 scripts anywhere in
the Netscape tree - php3 scripts are CGI programs in our configuration,
so we have to provide a service entry for them. Obviously that service
entry is not present in the standard configuration, because in the
standard configuration CGI programs can only be executed in the /cgi-bin
subtree.
So all you have to do is to add to the obj.conf file of your server an
entry like
<Object name="default">
...
Service method="(GET|HEAD)" type="magnus-internal/cgi" fn="send-cgi"
...
</Object>
just before all the other Service entries in your default object, after
you followed the kwazy installation description.
Step by Step installation instruction:
1. Compile the module as supplied. You get a file
redirect_cgi.so.
2. Install that file in
/opt/local/suitespot-3.0/https-ghost/plugins/redirect
or wherever your plugins directory is.
3. Do not change your magnus.conf as detailed in the
original installation instructions.
Instead add the following line to your obj.conf:
Init fn="load-modules" \
funcs="redirect-cgi" \
shlib="/opt/local/suitespot-3.0/plugins/redirect/redirect_cgi.so" \
NativeThread="no"
just after the other Init-directives in your obj.conf, before the
definition of the Default object.
Note the pathname, it must match the pathname from step 2.
You can stop and restart the server now, if you like. You can verify
that the module is loaded using /usr/proc/bin/pldd on the server process
on Solaris. You must get the redirect_cgi.so listed by pldd.
4. In your obj.conf locate the lines
ObjectType fn="type-by-extension"
ObjectType fn="force-type" type="text/plain"
in your default object. Insert the following line
between them:
ObjectType fn="redirect-cgi" \
cgi_path="/opt/local/www/cgi-bin/php" \
type="magnus-internal/php"
If you are using my version of that module, you have to add the
parameter 'debug="no"' or 'debug="yes"' to that line.
5. In your obj.conf, locate the lines
ObjectType fn="force-type" type="text/plain"
Service method="(GET|HEAD)" type="magnus-internal/imagemap"
fn="imagemap"
in your default objects and insert the following lines between them:
Service method="(GET|HEAD)" \
type="magnus-internal/cgi" \
fn="send-cgi"
as I explained above. This is the single step that is missing from the
original docs.
6. Also, to your mime.types file add the line
type=magnus-internal/php exts=php3,phtml
where appropriate (the section at the bottom where
all the other magnus-internal types are).
That is it.
------------------------------------------------------------
How can I get the details (tables, indicies, structure) of my Postgres
database from PHP?
http://e-gineer.com/e-gineer/phpkb/view.phtml/qid/566
------------------------------------------------------------
Bryan Ingram
I'm not sure if there are any other ways, but one thing you can do is
use the PHP "system" command to run psql or pg_dump as if you were at
the command line. At that point you can redirect the output
however/wherever you like.
------------------------------------------------------------
How can I include an image only if the file exists?
http://e-gineer.com/e-gineer/phpkb/view.phtml/qid/567
------------------------------------------------------------
Jason Brooke
Try this code using the file_exists function:
$photo = file_exists("/path/to/$playerid.jpg") ? "<IMG
SRC=\"/images/players/$playerid.jpg\">" : "No Photo Yet<br>\n";
http://www.php.net/manual.file_exists.php3
------------------------------------------------------------
Can I use PHP to do real streaming?
How can I generate .ram files using PHP?
http://e-gineer.com/e-gineer/phpkb/view.phtml/qid/568
------------------------------------------------------------
Michael Stearne, Manuel Lemos
PHP can't do streaming, but the QuickTime 4.0 Server (Darwin Streaming
Server) does stream using RTSP. It is free and can be compiled on
Intel machines. Go To
http://publicsource.apple.com
To generate .ram files all you have to do is set the content-type header
to audio/x-pn-realaudio and then output the media URL like this:
<?
Header("Content-Type: audio/x-pn-realaudio");
echo "pnm://realserver.adgrafix.com/users/ena/2001.rmd";
?>
The media URL maybe anything appropriate that your server may provide.
The regular Apache installation already assigns the MIME type
audio/x-pn-realaudio to files with the extenstion .ram . So you don't
need PHP to output fixed metadata files. Maybe you may want PHP to
generate metadata output depending on some parameters, like serving
different clips according to parameters defined in a form.
------------------------------------------------------------
How can I get all file names stored in a directory tree?
How can I recursively get the name and size of all files in a directory
and it's subdirectories?
http://e-gineer.com/e-gineer/phpkb/view.phtml/qid/570
------------------------------------------------------------
Robert Aden
I guess something like this would work. This functions returns the files
and size of them in the form file1=size&file2=size2 so it needs some
modification to just list them.
function sizeDirectory($directory) {
$dirhandle = opendir($directory);
while ( $entity = readdir($dirhandle)) {
if ($entity[0] == '.') {
// Do nutting unless dotfiles should count
} elseif ( is_dir($directory . '/' . $entity)) {
$ret .= sizeDirectory($directory . '/' . $entity);
} else {
$ret .= '&' . urlencode($entity) . '=' . (filesize($directory .
'/' . $entity));
}
}
return $ret;
}
** OTHER RANDOMLY SELECTED PHPKB ENTRIES **
------------------------------------------------------------
How can I get the number of rows returned by SELECT in Oracle?
http://e-gineer.com/e-gineer/phpkb/view.phtml/qid/177
------------------------------------------------------------
ora_numrows (and oci_numrows) are a bit misleading. There's no
way in oracle to tell how many rows are in a result set unless you:
a> read them all
or
b> do a select (*) [myquery] BEFORE issuing the real select.
That's the way it is in oracle (as well as in other "major" RDBMs
systems).
ora_numrows will give you the number of affected rows for an update
statement, and NOT the number of rows that are in a result set!
http://www.php.net/manual/ref.oracle.php3
------------------------------------------------------------
Why does sort() return things not sorted?
Why are my numbers from a database sorted in alphabetical order not
numerical?
http://e-gineer.com/e-gineer/phpkb/view.phtml/qid/504
------------------------------------------------------------
PHP treats the values from a database as strings by default. That means
that if you get numbers out, they will be treated as strings that just
happen to contain digits and they will be sorted in alphabetical order.
You can try changing them to numbers in a loop over your array using:
$a[$i] = intval($a[$i]);
http://www.php.net/manual/function.intval.php3
You could also use PHP's settype directive to force the "type" for all
processing on a page for that varname
Of course, for complex projects you can place all the settype directives
into a autoprepend file -- because I'll forever be forgetting about the
retyping that's needed on numerics from the database queries.
Here's the DOCs on that
http://www.php.net/manual/function.settype.php3
------------------------------------------------------------
What is the easiest way to write out an array to a file?
Is there any inverse of file(), that is, write out an array to a file?
http://e-gineer.com/e-gineer/phpkb/view.phtml/qid/189
------------------------------------------------------------
There is no inbuilt PHP function to write an array to a file. It is
easy to do though...
The long method:
function Array2File($ary, $filename) {
if (is_array($ary)) {
$fp = @fopen($filename, "w");
if ($fp > 0) {
while (list($key, $value) = each($ary)) {
fputs($fp, "$value\n");
}
fclose($fp);
}
}
}
Funky, short technique:
// assume $file is filled with something
$fd = @fopen("output","w") or die ("I/O error");
fwrite($fd,implode($file,"\n"));
fclose($fd);
------------------------------------------------------------
Can PHP be run using fast cgi?
http://e-gineer.com/e-gineer/phpkb/view.phtml/qid/374
------------------------------------------------------------
No PHP cannot be run under fastcgi.
------------------------------------------------------------
Where can I get a PHP Binary distribution for Windows?
http://e-gineer.com/e-gineer/phpkb/view.phtml/qid/7
------------------------------------------------------------
A useful link for all those on the Windows platform who want to use PHP
http://www.student.uni-koeln.de/cygwin
Has a binary distribution complied with MySQL (I think) and Apache plus
some other bits and pieces plus a good How To on compilation on Windows
with the GNU CC on Windows.
They have been told that when they fix a small problem with the server
not working correctly on Win95, it will become part of the standard
Apache distribution.
| Navigate in group php.kb at sever news.php.net | |
| Previous | Next |
| © No Copyright You are free to use Anything |
Site Maintained by Zareef Ahmed
Powered By PHP Consultants |