Home  |  Linux  | Mysql  | PHP  | XML
From:Nathan Wallace Date:Wed May 17 00:31:27 2000
Subject:[FAQTS] PHP Knowledge Base Update -- May 17th, 2000
More updates from:

    http://php.faqts.com

cheers,

Nathan


## Unanswered Questions ########################################


-------------------------------------------------------------
How to make MySQL support into an installed PHP without reinstalling other modules?(On apache, LINUX)
http://www.faqts.com/knowledge-base/view.phtml/aid/2900
-------------------------------------------------------------
William Holt



-------------------------------------------------------------
how to setup Apache to use PHP CGI with VirtualHosting and suEXEC?
http://www.faqts.com/knowledge-base/view.phtml/aid/2897
-------------------------------------------------------------
Amen Mok



-------------------------------------------------------------
How do I compile a dynamic loadable XML parser module for use under Unix?
http://www.faqts.com/knowledge-base/view.phtml/aid/1488
-------------------------------------------------------------
Philipp Reif, Fiona Czuczman, Matt Gregory



## New Entries #################################################


-------------------------------------------------------------
How do I format a MySQL timestamp into a readable date?
http://www.faqts.com/knowledge-base/view.phtml/aid/2926
-------------------------------------------------------------
Kay Crowley


I spent a couple of hours figuring this out even -with- plenty of 
available resources. Maybe this will help someone...

Change MySQL Timestamp (8char) into readable date

First, a UNIX_TIMESTAMP is not the same as a MySQL Timestamp. 
If you are using a MySQL Timestamp, you can use MySQL's DATE_FORMAT() 
Function to properly format it when you query your database.

As an example, DATE_FORMAT will render 'May 16, 2000' From a timestamp 
of '20000516'(and more per your own timestamp specs).

*YOUR QUERY:
 $query = "SELECT Field1,Field2,date_format(Timestamp_Field_Name, '%M %
d, %Y') AS Readable_Date,Field4 from Table_Name"; 
 
 [Note:  
 "date_format(Timestamp_Field_Name, '%M %D, %Y') AS Readable_Date" 
 is the critical piece here. Replace Timestamp_Field_Name with your 
own  timestamp field name.]
 
*YOUR IDENTIFICATION AS VARIABLE 
 [Massage to match your own coding/variables]
 
 $Field2 = mysql_result($result,$counter,"Field2"); 
 $Timestamp_Field_Name = mysql_result($result,$counter,"Readable_Date");
 $Field4 = mysql_result($result,$counter,"Field4"); 
 
*DISPLAY IN HTML PAGE
 PRINT  "$Timestamp_Field_Name";

For more information, refer to the MYSQL Docs:
http://web.mysql.com/Manual_chapter/manual_Reference.html
Do a find for DATE_FORMAT


-------------------------------------------------------------
How can I create a script that allows people to comment on products?
http://www.faqts.com/knowledge-base/view.phtml/aid/2950
-------------------------------------------------------------
Nathan Wallace
Richard Lynch

Untested code off the top of my head:

CREATE table comments(
  productid int4,
  comment text
);

product.php3
<?php
  $productid = 42;
  $product_name = 'widget';
  echo "<A HREF=comment.php3?productid=$productid>Comments</A> about
$product_name<BR>\n";
  $comments = mysql_query("select comment from comments where productid
= $productid") or die(mysql_error());
  while (list($comment) = mysql_fetch_row($comments)){
    echo $comments, "<HR>";
  }
?>

comment.php3
<?php
  if (isset($submit)){
    mysql_query("INSERT into comments(productid, comment)
values($productid, '$comments')") or die(mysql_error());
    echo "Thank you for your comment.<BR>\n";
  }
?>
<FORM ACTION=comment.php3 METHOD=POST>
  <TEXTAREA NAME=comments WRAP=VIRTUAL></TEXTAREA><BR>
  <INPUT TYPE=SUBMIT NAME=submit>
</FORM>


-------------------------------------------------------------
How do I use the gettext function?
http://www.faqts.com/knowledge-base/view.phtml/aid/2953
-------------------------------------------------------------
Nathan Wallace
chuck, Markus Harma

Here's a quick summary that assumes you already have the .mo files made:

1. if (!(isset($language))) {
      $language = select_lang();
   }
2. putenv("LANG=$language");
3. bindtextdomain('imp', './locale');
4. textdomain('imp');

Line by line:
1). select_lang() is a horde function that uses HTTP_ACCEPT_LANGUAGE and
a preference cookie that we set to negotiate what the language should
be.  Substitute something like: $language = 'fr' to just test french,
for example.

2). Set the LANG env variable. setlocale($language, LC_ALL) seems like
it ought to work, but it doesn't.

3). Tell gettext that we're looking for imp.mo files, and to search the
"locale" directory that's on the same level as this script. Note that
.mo files really need to be in ./locale/$language/LC_MESSAGES/imp.mo.

4). This seems to be somewhat redundant with the last call, but both are
needed.  Someone who's used gettext in other environments care to
explain it to me? =)

Now, just use echo _("string") instead of echo "string" (or the long
form, gettext("string")), and you should be all set.

I hope this helps you out. Btw, you compile --with-gettext to get the
support - I don't know if it was in 3.0.7, but if not, I'm sure you can
find many other reasons to upgrade. :)


-------------------------------------------------------------
How do I create a dynamic hyperlink in PHP?
http://www.faqts.com/knowledge-base/view.phtml/aid/2898
-------------------------------------------------------------
Nasser Ghoorun, Matt Gregory, Nathan Wallace


Standard hyperlink echoed in PHP
echo "<a src=\"http://www.mysite.com/index.html\">mysite</a>";

Dynamic hyperlink echoed in PHP where $urlvar is the variable URL.
echo "<a src=\"$urlvar\">$urlname</a>";


-------------------------------------------------------------
How can I control error handling in PHP?
Can I log all PHP errors to a file?
http://www.faqts.com/knowledge-base/view.phtml/aid/2961
-------------------------------------------------------------
Nathan Wallace
Paul Fotheringham

You can control how errors get written out with the php3.ini (or
equivalent) configuration file. Look for a section named something like
"Error Handling and Logging". On my set-up I have:

  display_errors = Off
  log_errors = On
  error_log = whatever/file/you/want/to/use


-------------------------------------------------------------
How can I use a global variable inside a class?
http://www.faqts.com/knowledge-base/view.phtml/aid/2962
-------------------------------------------------------------
Nathan Wallace
Wico de Leeuw

It's exactly the same as accessing global variables in functions:

    class Globals {
         function show_self() {
             global $PHP_SELF;
             print $PHP_SELF;
         }

    }

should do the trick.


-------------------------------------------------------------
How can I set the language and char sets in the HTTP headers?
Where can I get more information about building international web sites?
http://www.faqts.com/knowledge-base/view.phtml/aid/2965
-------------------------------------------------------------
Nathan Wallace
Rob Hardowa

I haven't looked into this too much yet, but here's a good site about
it:

   http://www.isoc.org:8080/

I'm doing a multi-lingual site at the moment that doesn't require any
special character set so I just send these out in the <HEAD>:

<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1">
<META HTTP-EQUIV="Content-Language" CONTENT="{LANGUAGE}">

According to the site I just gave you they recommend sending out the
CONTENT="text/html; charset={yourcharset_UTF-8_orwhatever}" part of it
in the header.


-------------------------------------------------------------
How can I do simple natural language processing with PHP?
How can I parse queries to remove natural language?
http://www.faqts.com/knowledge-base/view.phtml/aid/2966
-------------------------------------------------------------
Nathan Wallace
Michael Dearman, Steve Edberg

Take a look at the perl regular expression support. The preg's. 'THE'
ref on regular expressions (IMHO) is Jeff Friedl's "Matering Regular
Expressions", O'Reilly. A most 'unnatural' language. But, that'd be one
possibility.

And, to add my .02 intergalactic creds:

I second the recommendation for Freidl's 'Mastering Regular 
Expressions', avaliable from O'Reilly. While it focuses mostly on 
Perl-style regexes (implemented in PHP's preg_...() functions; see 
http://www.php.net/manual/ref.pcre.php), it also briefly covers the 
POSIX-style expressions used in PHP's ereg_...() functions 
(http://www.php.net/manual/ref.regex.php).

For other natural-language processing tools, check out the list 

  http://www-a2k.is.tokushima-u.ac.jp/member/kita/NLP/nlp_tools.html

or the 'Unix for Linguists' page at

  http://www-personal.umich.edu/~jlawler/routledge/regex.html

For more links, just run the AltaVista query

http://www.altavista.com/cgi-bin/query?sc=on&hl=on&kl=XX&pg=q&text=yes&q=%2B%22regular+expressions%22+%2Blinguistic*


-------------------------------------------------------------
How can I build WAP services with PHP?
http://www.faqts.com/knowledge-base/view.phtml/aid/2967
-------------------------------------------------------------
Nathan Wallace
Matt Wiseman

There was an interesting article in Web Techniques regarding WAP and ASP
that i highly recommend..  Mind you its not PHP, but as both platforms
are so similar functionality-wise, you should be able to more than gleam
something from that

  http://www.webtechniques.com/archives/2000/03/passani/


-------------------------------------------------------------
How can I produce WML from PHP?
http://www.faqts.com/knowledge-base/view.phtml/aid/2968
-------------------------------------------------------------
Nathan Wallace
SANIsoft

Here is a simple example of how I spew out WML using PHP3.  As an added
factor - I am using PHPlib for authentication. Check out the WML FAQ for
more on using PHPlib authtentication with WML- search the list archive
for the URL

=====================================================
<?php
header("Content-type: text/vnd.wap.wml"); // Tell browser that I am
sending
wml
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); //We dont want the
protected pages to be cached
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
page_open(array("sess" => "redwap_Session",
                 "auth" => "redwap_Auth")); // This is the call to
PHPlib
for starting session and Authentication code
echo("<?xml version=\"1.0\"?>\n"); // This could have been below hard
coded
:-)
echo("<!DOCTYPE wml PUBLIC \"-//WAPFORUM//DTD WML 1.1//EN\"
\"http://www.wapforum.org/DTD/wml_1.1.xml\">\n");
?>
<wml>
<card id="edit" title="redDiary">
<p><anchor>Search
<go href="search.php3" />
</anchor>
</p>
<p><anchor>Add Contact
<go href="addcontact.php3"/>
</anchor></p>
<p><anchor>Send Email
<go href="sendmail.php3" />
</anchor>
</p>
<p><anchor>Log Out
<go href="logout.php3" />
</anchor>
</p>
<p><img src="msi.wbmp" alt="MSI Logo" />Menu<img src="ss.wbmp" alt="SS
Logo"
/>
</p>
</card>
</wml>
<? page_close() ?> // Do not forget to close all your pages
=============================================


## Edited Entries ##############################################


-------------------------------------------------------------
how can I proceed to implement chat using PHP3.0?Any related link for my query?
http://www.faqts.com/knowledge-base/view.phtml/aid/1518
-------------------------------------------------------------
Shachi, Matt Gregory


Your best bet for implementing chat with PHP is to set up a relational 
databse for users, messages, and threads.

I would design this application with these interfaces:
  - Read message module
  - Post message module
  - Browse all messages
  - Browse thread
  - Mail management modules
  - User management modules
  - Help modules

This is an extensive project.  Expect it to take you a week or more to 
write.  Then, open source it so I can use it too.  :)


-------------------------------------------------------------
where can i find information for creating web based unix administration pages through php?
http://www.faqts.com/knowledge-base/view.phtml/aid/1874
-------------------------------------------------------------
Dave Garth, Matt Gregory


PHP is not commonly used to administrate servers.
The reason for this is because most servers do not put administrative 
scripts on an internet/intranet because of security related issues.  
There are, however, many script resources available on the web ( 
http://www.listproc.net/scripts/ , 
http://wundt.kfunigraz.ac.at/rath/documentation/node44.html )

PHP specifically is not used often for system administration because 
that was not what it was designed for.  PHP is intended to quickly 
parse and return web pages.  It does not have the fastest file i/o and 
system communication routines in the scripting language category.

With that said, now that you are in the areana do you mind starting a 
site and posting any scripts you create?  :)

PS: members of www.phpwebhosting.com (like myself) have access to many 
php administrative scripts, but they are proprietary.  You might want 
to look at currently available pearl, c++ cgi, and other web admin 
tools to get ideas before pounding something out in php.


-------------------------------------------------------------
how do i compare and check the user input password from form with encrypted one in the Apache htaccess password file
http://www.faqts.com/knowledge-base/view.phtml/aid/2141
-------------------------------------------------------------
Nikhil Mehta, Matt Gregory


The .htpasswd file containes users in a linear list as shown below

<username>:<encrypted-password><cr> where <cr> is carriage return.

In order to compare the encrypted-password to your user-entered 
information you must first encrypt the password using the mcrypt 
function.

Remember that you cannot decrypt the encrypted information in 
the .htpassword file.  (at least not easily :) )


-------------------------------------------------------------
I have made a web page generator, I'm having trouble trapping the parsed php3 file and saving it as a normal html file on the server..any ideas???
http://www.faqts.com/knowledge-base/view.phtml/aid/2271
-------------------------------------------------------------
Dave Murad, Matt Gregory


Well, not that this is a normal thing to do with PHP, but your best bet 
is to print all the text you return to the browser out to an open file 
stream as well (open with fopen, write with fwrite).

Some hosts will not allow you to do this since it is a security issue.

Your second option is to do what all the Search engines do.  Hit the 
url of the html generation script and then, once you do your get 
command, save the returned information to blah.html. (where blah is the 
name you want to call the html file.)

I would not name PHP as the best tool for getting and writing the html 
file.  This is something better suited for perl or python.


-------------------------------------------------------------
When I try to run a script I've got a message box saying "couldn't find MSVCRTD.dll library in specified path <win path env>". What's going here?
http://www.faqts.com/knowledge-base/view.phtml/aid/2555
-------------------------------------------------------------
Valmir Cinquini, Matt Gregory


MSVCRTD.dll is a microsoft runtime library containing much of the 
microsoft foundation classes implementation code.  It is usually 
distributed with any application which use it.

Do a search on your HD for the file, if you find it, you need to move 
it into your path.  This can be done by moving the file to your 
$:\windows\system or $:\winnt\system32 folder.

If you do not have the file then go to microsoft's webiste and download 
it or extract it off your installation cd.  (msvcrtd.d_)


-------------------------------------------------------------
how can I split year digits into 4 variables
http://www.faqts.com/knowledge-base/view.phtml/aid/2843
-------------------------------------------------------------
Peter Morrissette, Henrik Jönsson, Richard Heyes
http://www.php.net/manual/function.substr.php

$var_year = date("Y");

$var_digit1 = substring($var_year,0,1);
$var_digit2 = substring($var_year,1,1);
$var_digit3 = substring($var_year,2,1);
$var_digit4 = substring($var_year,3,1);

Or

$var_year = date("Y");

$var_digit1 = $var_year[0];
$var_digit2 = $var_year[1];
$var_digit3 = $var_year[2];
$var_digit4 = $var_year[3];


-------------------------------------------------------------
How can I send an email in both txt and HTML format and have only 1 be display in the users email program?
http://www.faqts.com/knowledge-base/view.phtml/aid/2775
-------------------------------------------------------------
Michael Bell, Matt Gregory, Richard Heyes


You need to choose which one the user is going to see first, and make 
the second an attachment to the first.

Or send a multipart email using mime. Here's a class that will help:

http://phpclasses.upperdesign.com/browse.html/package/32


-------------------------------------------------------------
How could I echo a variable which include "<? XXX ?>"
http://www.faqts.com/knowledge-base/view.phtml/aid/1876
-------------------------------------------------------------
Matthew Ma, Matt Gregory, Nathan Wallace


I can see where this one would cause you trouble.

You have to avoid two parsing conflicts when you echo this return 
variable.  First, php sees <? as the beginning of a script, and it 
sees ?> as the end of a script.  To avoid this problem make sure that 
the return variable is inside of quotes like a string "<?".

Your second problem is the browser itself, which sees < as the 
beginning of an HTML tag.  You need to change any "<" returned to the 
browser to "&lt;" and any ">" to "&gt;".


-------------------------------------------------------------
Is it possible to PUSH content through PHP3 like the server time every second?
http://www.faqts.com/knowledge-base/view.phtml/aid/1935
-------------------------------------------------------------
Chris Schmidt, Matt Gregory, Nathan Wallace


Yes and No.
Using PHP alone, this is not possible.  PHP is run when a file with an 
associated extention is called.  For this reason it is impossible to 
have Server events triger PHP.  You could do one of two things to make 
this happen however:

 1.) Create a server-side module (Apache & IIS) or a Service (NT) to 
call your script on a timed basis or...
 2.) Have a webpage refresh every X seconds thereby calling the 
generating script.


-------------------------------------------------------------
How to pass login and password from first level script to third level script (that means one script is included in another,like that 3 levels)?
http://www.faqts.com/knowledge-base/view.phtml/aid/1961
-------------------------------------------------------------
Samatha Kottha, Matt Gregory, Nathan Wallace


This is one of the most difficult problems for new users of PHP to 
understand.  PHP is called when the page is called, and then closes 
once the page has been returned to the client.  There are three 
possible ways to handle the problem of passing information between 
script files.

1.) return the variables to the browser as a hidden field in a form.  
You can decide whether or not to encrypt this information before 
plopping it into the HTML.

2.) return the variables in temporary cookies (make sure it is 
temporary.) and then delete the cookies when the user leaves the site.

3.) store the variables, encrypted or not as you prefer, in a database 
table of logged-in users or sessions.

There are other ways of doing this, but they are much harder and in my 
opinion not worth the trouble.


-------------------------------------------------------------
How can I add/write to an existing file?
http://www.faqts.com/knowledge-base/view.phtml/aid/2650
-------------------------------------------------------------
Peter Morrissette, Henrik Jönsson, Nathan Wallace


I generally do this (perhaps not the best way of doing it, but it 
works!):

Read the file you want to change into an array (or string).

Then add the changes to it accordingly (ofcourse this means you have to 
know where to add it) then write the file again.

Ex. (to add at the end of the file);


// set where the file is located
$file_path = "filepath & filename";


// start reading in the file into the array
$fileopen = @fopen($file_path, "r");

if (!$fileopen) { echo "Can't open file"; }

for ($i=0; $buffer = fgets($fileopen, 16192); $i++) {
  $arr_file[$i] = $buffer;
}

fclose($fileopen);


// this is what you want to add
$str_toadd = "This i want to add";


// write the file
$fileopen = @fopen($file_path, "w");
  for ($i=0; $i < sizeof($arr_file); $i++) {
    fwrite($fileopen, $arr_file[$i], 16192);
  }
  fwrite($fileopen, $str_toadd, 16192);
fclose($fileopen);

As said earlier, probably a bit messy, but I've had no worries using it.



Navigate in group php.kb at sever news.php.net
Previous Next




  
© No Copyright
You are free to use Anything
Site Maintained by PHP Developer
Powered By PHP Consultants