|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread |
Rating:
|
Display Modes |
|
|
|
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
|
|
#16
|
||||
|
||||
|
#32 Since I upgraded to 4.2 I get Undefined Variable errors. Why?
Not a bug - feature Those are not errors, those are warning for you, as programmer, so you keep track of which variables are used before being initialized or which ones are not being set. If you want to fix this, edit you php.ini and set error_reporting = E_ALL & ~E_NOTICE Alternativly you could use error_reporting() run-time or php_value error_reporting "E_ALL & ~E_NOTICE" in .htaccess Although it might be a good idea to leave warnings while still in developing phase.
__________________
And you know I mean that. |
|
#17
|
|||
|
|||
|
#33 HELP! I need to remember my form values after submit!
I have seen a lot of posts around here lately on how to remember form values after the user hits "submit" [so that they can be corrected]. Well the method that I use is very simple: I store my form in a function, and then when I need to display it I just call that function. After a presses submit, I just display the form the submitted values in it. Easy as pie! ![]() Here is an example (this is kinda long ):PHP Code:
Please note: This code is untested, but it should work! ![]() Cheers, Joe of 4Life ![]() |
|
#18
|
||||
|
||||
|
How Do I Set Up Php As An Isapi Module?
#34 HOW DO I SET UP PHP AS AN ISAPI MODULE?!
See this interesting (and clear) explaination Configuring IIS to Use PHP [Moderator's Note: The installation chapter of the manual details the exact same procedure] #34bis HOW DO I SET UP PHP AND APACHE ON WINDOWS?! See this document (link posted by delboy_trotter) #34 Ammendment Ready built WAMP (Windows, Apache, MySQL and PHP) packages can be found here: http://hotscripts.com/PHP/Scripts_a...tallation_Kits/ #34c HOW DO I SET UP PHP INSIDE TOMCAT?! This is how I did it Php and Tomcat
__________________
My blog about OpenSource Databases PDF tutorials about OSS databases, DBMonster ... Please contribute to Open Source Development, fill bug reports!!! Developer Shed eSupport Commented my.ini/my.cnf (PLEASE ADD YOUR OWN CONFIG TRICK) Understanding SQL Joins An introduction to database normalization Natural or Surrogate key Custom ordering for your results Correlated and uncorrelated subqueries |
|
#19
|
||||
|
||||
|
#35 FORM FIELD VALIDATION
This is a function that can easily be cut and pasted into your code to validate form field data returned from a user. Example of use: field_validator("Email Address", $email, "email", 5, 255, 1); parses the string contained in $email to make sure it is of type 'email', between 5 and 255 characters long, insisting the field is required. Any errors found are stored in the global array $messages. Code:
function field_validator($field_descr, $field_data, $field_type, $min_length="", $max_length="", $field_required=1) {
# array for storing error messages
global $messages;
# first, if no data and field is not required, just return now:
if(!$field_data && !$field_required){ return; }
# initialize a flag variable - used to flag whether data is valid or not
$field_ok=false;
# a hash array of "types of data" pointing to "regexps" used to validate the data:
$data_types=array(
"email"=>"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$",
"digit"=>"^[0-9]$",
"number"=>"^[0-9]+$",
"alpha"=>"^[a-zA-Z]+$",
"alpha_space"=>"^[a-zA-Z ]+$",
"alphanumeric"=>"^[a-zA-Z0-9]+$",
"alphanumeric_space"=>"^[a-zA-Z0-9 ]+$",
"string"=>""
);
# check for required fields
if ($field_required && empty($field_data)) {
$messages[] = "$field_descr is a required field.";
return;
}
# if field type is a string, no need to check regexp:
if ($field_type == "string") {
$field_ok = true;
} else {
# Check the field data against the regexp pattern:
$field_ok = ereg($data_types[$field_type], $field_data);
}
# if field data is bad, add message:
if (!$field_ok) {
$messages[] = "Please enter a valid $field_descr.";
return;
}
# field data min length checking:
if ($field_ok && $min_length) {
if (strlen($field_data) < $min_length) {
$messages[] = "$field_descr is invalid, it should be at least $min_length character(s).";
return;
}
}
# field data max length checking:
if ($field_ok && $max_length) {
if (strlen($field_data) > $max_length) {
$messages[] = "$field_descr is invalid, it should be less than $max_length characters.";
return;
}
}
}
For a demo and more details check here: http://validator.munk.nu/ Thanks go to the user raydenx who wrote the original function in this thread. |
|
#20
|
||||
|
||||
|
Re: #30 How do i str_replace thats not case sensitive
Quote:
FYI: It's considerably faster to just use preg_replace() and use "i" as a pattern modifier to make the search case insensitive. $b = preg_replace("/this/i","that",$string); ---John Holmes... |
|
#21
|
||||
|
||||
|
Quote:
I think that's because PHP treats it like a floating point integer whre the first digit is the whole number and the rest of them are places after an invisible decimal point. Am I correct? Sorry if someone has already posted this. I didn't read the entire thread. Furry |
|
#22
|
||||
|
||||
|
#36 How to schedule PHP scripts
Since this is a common question in the forums, I'm writing down my solution for this in the hope it helps others. It has been developed on Windows but it should provide hints to *nix users also. It works for every version of php, not only CGI and on remote servers also. 1. Download and install CRON for Windows from http://www.kalab.com/freeware/ (there is a version that runs as a service) 2. Download various Unix utilities for Windows from http://unxutils.sourceforge.net/ and install (copy) WGET 3. Choose a working php script to be run, mine is something like: PHP Code:
4. Create a batch file like this (scheduler.bat): C:\usr\local\wbin\wget.exe --spider --quiet http://host/path/file.php (--spider means "don't download anything" and --quite means "no output") 5. Add an entry for it in crontab file, like: # select into outfile every day at midnight 0 0 * * * C:\usr\local\wbin\scheduler.bat 6. CRONTAB and the log file for cron service are located in c:\WINNT\system32 Please PM me any suggestions/comments about this! |
|
#23
|
||||
|
||||
|
#36 How to schedule PHP scripts (cont.)
If you're on Windows, you can also use the built in Task Scheduler program to run a command such as: c:/php/php.exe -q c:/path/to/php/file.php Which will run your script according to the schedule you choose. Every installation of PHP has an .exe file, even if it's installed as a module. Also, newer versions of PHP have the CLI version that can be used for this, too. Another alternative would be to run iexplore.exe and call up your page, which would be similar to the wget/lynx method commonly used. c:/winnt/iexplore.exe http://localhost/path/to/file.php For this option, you'll want to check the box that says "End program after X minutes" so that IE will shutdown after so many minutes. ---John Holmes... |
|
#24
|
||||
|
||||
|
#36 works under MacOS X's Unix terminal too:
% open /Applications/Internet/Internet\ Explorer.app http://localhost/path/to/file.php
__________________
TommyWillB Apple Power Mac G4 867mhz, 1GB RAM nVIDIA geforce 2 (TwinView) Apple Studio 17" flat screen + Compaq 17" 2x60GB ATA drives jeffntom.com hosted on Mac OS X 10.3.4 / Apache 1.3.29 / PHP 4.3.2 |
|
#25
|
|||
|
|||
|
Re: Re: #30 How do i str_replace thats not case sensitive
#30 How do i str_replace thats not case sensitive
isn't it even easier to use eregi_replace() function? PHP Manual reference |
|
#26
|
||||
|