PHP Beginners Tutorial

  • PHP discovered by Rasmus Lerdorf in 1995
  • PHP is a server-side scripting language
  • PHP is an acronym for “PHP: Hypertext Preprocessor”.

PHP Syntax :

A PHP script starts with <?php and ends with ?>

PHP also allows for short open tags <? and ?> (which are discouraged because they are only available if enabled with short_open_tag php.ini configuration file directive, or if PHP was configured with the –enable-short-tags option.

My First PHP Program :

The default file extension for PHP files is “.php”

Output :

Hello wikistack!

echo and print Statements :

echo - can output one or more string.
print - can output one string and return always 1.

**NOTE** – echo is faster compare to print, echo does not return any value.

PHP String Function :

Some important string functions :

1. strlen() : is used to find the length of string.

example :

Output : 15

2. strpos() : return the character position of the first match.

example :

Output : 6

**NOTE** –┬áThe position of the string “world” in the example above is 6. The reason that it is 6 (and not 7), is that the first character position in the string is 0, and not 1.

3. wordwrap() : wrap a string into a newline.

syntax :

wordwrap(string, width, break, cut)
*cut-> optional-> TRUE - wrap
               -> FALSE - default (no wrap)

example :

Output : Hel
         lo
         wik
         ist
         ack

To be continue…soon




Related Contents to follow