WordPress database error: [Table 'wp_comments' is marked as crashed and should be repaired]
SELECT ID, COUNT( comment_ID ) AS ccount FROM wp_posts LEFT JOIN wp_comments ON ( comment_post_ID = ID AND comment_approved = '1') WHERE ID IN (29,25,28,27,26) GROUP BY ID

PhpTutorialSite.com http://phptutorialsite.com Learning Php made easier with our php tutorials Mon, 04 Aug 2008 02:44:03 +0000 http://wordpress.org/?v=1.5.2 en Php Get Method http://phptutorialsite.com/php-get-method.htm http://phptutorialsite.com/php-get-method.htm#comments Mon, 04 Aug 2008 02:25:10 +0000 phpdeveloper Advanced PHP Tutorials http://phptutorialsite.com/php-get-method.htm We will take a more in depth look into “GET” function. When the form action uses the “GET” method the browser appends the the values the user placed in the form in the URL. I am sure all of you have seen a browser with a long url comprising on “=” and “?” in a serious of combinations , and if you every took a details looked you would probably seen some of the information that you typed in amongst the confusing looking url.

Let’s make some sense of the string, it follows the format of variables name and value. So in the string or as it is technically known is called the “query string”.
url/getform.php?website=phptutorialsite.com&toturiallanguage=php
This means that the value of the variable website = phptutorialsite.

You will notice that that i added in an “&”. The “&” means that we have added another variable into the url, so we are “adding other variables to the string.

So that string reads.
website = phptutorialsite.com
toturiallanguage = php

That was just a simple example, but things can get very complex when you have string with spaces and characters. Filled with characters and spaces and symbols. With this said we enter the world of URL ENCODING. This website will give you the codes used in encoding characters into an URL
http://www.w3schools.com/TAGS/ref_urlencode.asp

The beauty of the encoding is that it is all done automatically so when you are developing and using the GET function you don’t need to worry about doing the url encoding.

In your php file, in out case would be “getform.php” you will just use the variables
echo $website and echo tutoriallanguage.

The disadvantage or problem with using the GET method is that the information is passed through the URL and there is a limit to how much information you can pass in the URL.

]]>
http://phptutorialsite.com/php-get-method.htm/feed/
Strings in Php http://phptutorialsite.com/string-in-php.htm http://phptutorialsite.com/string-in-php.htm#comments Sun, 13 Jul 2008 19:05:33 +0000 phpdeveloper Intro PHP Tutorials http://phptutorialsite.com/string-in-php.htm Strings in PHP

After integer.. maybe just after integer, strings are possibly the most important variable types in programming. Storing a bunch (series) of character as one variable. PHP give you alot of functions to manipulate and handle strings.

You can think of string as an array of characters, and individuals characters can be accessed using the index of the character withing the string.

< ?php

$my_string = 'My First String in Php';
$our_string = "My Second String in Php";

$h = "Hello";
$w = "World";
$hw = $h . $w; // appending Hello and World
$h .= $w; // Hello World appending world to hello

$first_letter = $hw[0];
$last_letter = $hw[strlen($hw)-1];

?>

In printing the last character in my string the function strlen was used. Strlen, return the lenght of the string as an integer. So we used the length of the string minus 1, since we are using arrays that start at 0, to get the last character of the string.

Next very useful function is chr, which takes the ascii value and translate it into a string. You can use chr to generate very good passwords

< ?php
$password_len = 5;
$password = "";
$inex = 0;
while($index <= $password_len)
{
$password .= chr(rand(33,126));
$index++;
}
echo $password;
?>

You can check the ASCII-table at http://www.asciitable.com

More string manipulation

Getting Rid of White Space or other Characters

string rtrim ( string str [, string charlist] )
string ltrim ( string str [, string charlist] )
string trim ( string str [, string charlist] )

[, string charlist] optional paramater

rtrim — Strip from the end of a string
ltrim — Strip from the beginning of a string
trim — Strip from the beginning and end of a string

These function returns a string with whitespace stripped from the beginning and end of str. Without the second parameter these functions will strip these characters

” ” (ASCII 32 ), an ordinary space.
“\t” (ASCII 9 ), a tab.
“\n” (ASCII 10), a new line (line feed).
“\r” (ASCII 13), a carriage return.
“\0″ (ASCII 0 ), the NUL-byte.
“\x0B” (ASCII 11 ), a vertical tab.

Sub-String, String-Replace, Change Case

Changing Case

strtoupper() // Changes a string to Upper Case
strtolower() // Changes a string to lower case

These to functions speak for themselves (very good function naming)

ucwords — Uppercase the first character of each word in a string
The definition of a word is any string of characters that is immediately after a whitespace (These are: space, form-feed, newline, carriage return, horizontal tab, and vertical tab).

ucfirst — Make a string’s first character uppercase

Sub-String

Substring (Substr), return the string, starting at the position defined by the start and either to the end of the string or the number of characters defined in the third parameter.

string substr ( string string, int start [, int length] )
[,int length] optional paramater

$orig_string = “phptutorialsite.com” ;

$first_part = substr($orig_string,0,3); // php
$last_part = substr($orig_string,3,16) ; //tutorialsite.com

Strstr & Stristr — Find first occurrence of a string

Strstr and Stristr (case-insensitive searches) returns the part of the string from the first occurrence of the string being searched for until the end of the string. If the string is not found the function returns FALSE (boolean).

string strstr (string where_to_look, string what_to_find)
$orig_string = “phptutorialsite.com”;
$php_tutorial = stristr($orig_string, “php”); //tutorialsite.com

$what_to_find = “PHP”;
$where_to_look = “php Tutorial Site “;

if(strstr($where_to_look,$what_to_find))
{
echo “Yes I found Php Tutorial in this string on this php tutorial site.”;
}
else
{
echo “Php not in this string.”;

}

StrPos - Find position of first occurrence of a string
int strpos ( string where_to_find, mixed what_to_find [, int offset] )

This works just like strstr, however this return the position of the search string within main string. If the string is not found strpos returns FALSE (boolean).

Implode and Explode
The last 2 functions we are going to cover in this tutorial are explode () and implode (). These functions are used in converting strings to arrays and arrays to strings.

Explode takes the elements in a string “seperated” by delimiter and places those elements into an array.

e.g It can take a date 07/08/2006 and put it into an array date, where date[0] = 07, date[1]=08 and date[2]=2006, where “/” is the delimiter.

eg.
string siteurl = “www.phptutorialsite.com”;

$site=explode(”.”, $siteurl);

site[0]=> www
site[1]=> phptutorialsite
site[2]=> com

Implode takes the element of an array, and put them into a string, with the “separator” being the first parameter specified in the implode functions.

e.g

sitename[0]=php
sitename[1]=good
sitename[2]=tutorial
sitename[3]=site
sitename[4]=best

$sitefullname= implode (” “, $sitename);
echo $sitefullname; //php good tutorial site best

Syntax :
explode() => array explode ( string separator, string string [, int limit] )
implode() => string implode ( string glue, array pieces )

Closing
These are just a few of the functions, that can be used to manipulate strings in php, for a full list of string function, you can visit. http://www.php.net/manual/en/ref.strings.php .

]]>
http://phptutorialsite.com/string-in-php.htm/feed/
Php Variables Test Functions http://phptutorialsite.com/php-variables-test-functions.htm http://phptutorialsite.com/php-variables-test-functions.htm#comments Sun, 13 Jul 2008 15:54:41 +0000 phpdeveloper Advanced PHP Tutorials http://phptutorialsite.com/php-variables-test-functions.htm Php provides isset, unset and empty that can help you when you use variables in php programming and coding. These variables will give you the status of a variable, if it is in use, created, or when you want to get rid of the variable.

isset()
Isset is used to show the user if a variable has be created. Isset() will return the value of 1, if the variable is created. If the variable is not created, nothing will be returned by Isset.

echo isset($myVar);

empty()
Empty, is logically opposite to isset, and it provided a little more information on the variable.
If the variable is not created empty return the value of 1, if the variable is define and has the value (0, or “” (null/empty string)) empty returned the value of 1 as well. However if the variable is defined empty does not return any values.

echo empty($myVar);

unset()
Unlike isset and empty, which just returns a value, unset acts on the variable. Unset cleared the varaible from memory and unallocated the variable. The variable name and the value of the variable is completed erased when using unset.
Thus great care should be used when using the function unset, and you should be sure that you dont require that variable or its vale anywhere else in the program.

]]>
http://phptutorialsite.com/php-variables-test-functions.htm/feed/
Variable Type Casting In Php http://phptutorialsite.com/variable-type-casting-in-php.htm http://phptutorialsite.com/variable-type-casting-in-php.htm#comments Sun, 13 Jul 2008 15:34:58 +0000 phpdeveloper Advanced PHP Tutorials http://phptutorialsite.com/variable-type-casting-in-php.htm As we showed you before, variables in PHP do not have to be defined as in some other programming languages. How are they are some instances where you want to force a variable into a particular type as oppose to having PHP assigned the data type for you. This is called variable casting. The following in an example of casting in PHP,

$myVar = 8;
$myVar = (string) $myVar ;
$myVar = (integer) $myVar;

gettype, settype

Gettype and settype, can be used to to do the variable castinig for you in PHP as well as get the current datatype of the variable. Gettype as the name implies get the variable type for the current variable

$myNum = 8;
echo gettype($myNum) ;
This will display the value “integer” as the type of the variable.

settype($myNum, “string”);
echo gettype ($myNum);
This displays the value “string”.

]]>
http://phptutorialsite.com/variable-type-casting-in-php.htm/feed/
Constants In PHP http://phptutorialsite.com/constants-in-php.htm http://phptutorialsite.com/constants-in-php.htm#comments Sun, 13 Jul 2008 15:09:37 +0000 phpdeveloper Advanced PHP Tutorials http://phptutorialsite.com/constants-in-php.htm In some cases, you will need to define global variables or constants who values will not change during the execution of the php code. Php provides you will the ability to define constants using the Define Keyword. The CONSTANTS are defined a differently to normal variables. They start with the DEFINE keyword and do not contain a “$”.

define (”NEWYEARSDAY, “January 1st”);
define (”MONTHSINYEAR”, 12);
define(”NUMBEROFALPHABETLETTERS”26);

Examples of how to display constants.

echo “The number of letters in the alphabet are ” . NUMBEROFALPHABETLETTERS ;

echo “New years is generally celebrated on ” . NEWYEARSDAY;

echo PHP_OS; Displays the current (OS) operating system that PHP is running.

PHP has a few define constants, sometimes refer to as magic constants.

__LINE__
The current line number of the file.
__FILE__
The full path and filename of the file. If used inside an include, the name of the included file is returned. Since PHP 4.0.2, __FILE__ always contains an absolute path with symlinks resolved whereas in older versions it contained relative path under some circumstances.
__DIR__
The directory of the file. If used inside an include, the directory of the included file is returned. This is equivalent to dirname(__FILE__). This directory name does not have a trailing slash unless it is the root directory. (Added in PHP 5.3.0.)
__FUNCTION__
The function name. (Added in PHP 4.3.0) As of PHP 5 this constant returns the function name as it was declared (case-sensitive). In PHP 4 its value is always lowercased.
__CLASS__
The class name. (Added in PHP 4.3.0) As of PHP 5 this constant returns the class name as it was declared (case-sensitive). In PHP 4 its value is always lowercased.
__METHOD__
The class method name. (Added in PHP 5.0.0) The method name is returned as it was declared (case-sensitive).
__NAMESPACE__
The name of the current namespace (case-sensitive). This constant is defined in compile-time (Added in PHP 5.3.0).

]]>
http://phptutorialsite.com/constants-in-php.htm/feed/