PHPComments (0)

PHP which is short for PHP: Hypertext Preprocessor is a very popular and open source, server-side, HTML embedded scripting language used to create dynamic Web pages.


You need sign in to comment! Sign up today!

Functions to help ut with strings!Comments (0)

These PHP functions can help you control the strings:

Strip HTML and PHP tags from a string

Convert special characters to HTML entities

Convert all applicable characters to HTML entities

Inserts HTML line breaks before all newlines in a string

Strip whitespace (or other characters) from the beginning and end of a string

What is a string?

At the lowest level a string is an array of the type char. Every char is one byte large and together they make so called "strings".

sizeof(char) = 1

Char array - One form of strings

char str[6] = "Hello"; //Size is 6 because of the terminating null character '\0'

String litteral - Another form of strings
There is also an other form called a 'string litteral'. It is basically a pointer to a char array residing in read-only memory.

char * str_l = "Hello"; //Note: no size specified during initialization

Modfiy strings

Since string litterals are stored in read-only memory you are not able to modify them.

On the other hand, char arrays can be modified using the string.h function 'strcpy(char *, const char *)'.

char str[6] = "Hello";
puts(str); //Prints 'hello'

//Change value
strcpy(str, "new");
puts(str); //Prints 'new'


You need sign in to comment! Sign up today!