You are on page 1of 3

String Manipulation and Regular Expressions

---------------------------------------------------------------------------------------In your CSS use this (for textareas): To disable resisable textarea!!
textarea {
resize: none;
}
---------------------------------------------------------------------------------------mail();
chop();
ltrim();
rtrim();
trim();
nl2br();
printf();
sprintf();
strtoupper()
strtolower()
explode() : $email_array = explode( @ , $email);
implode() : $new_email = implode( @ , $email_array);
get_magic_quotes_gpc() - This capability is controlled by the magic_quotes_gpc c
onfiguration
directive in its name.The letters gpc, which is turned on by default in new inst
allations
of PHP, stand for GET, POST, and cookie.This means that variables coming from
these sources are automatically quoted.You can check whether this directive is s
witched
on in your system by using the get_magic_quotes_gpc() function, which returns tr
ue
if strings from these sources are being automatically quoted for you. If this di
rective is on
in your system, you need to call stripslashes() before displaying user data; oth
erwise,
the slashes will be displayed.
---------------------------------------------------------------------------------------substr() - substr($a,0,5) - starting from 0th character copy 5 characters;
---------------------------------------------------------------------------------------strtok() - Unlike explode(), which breaks a string into all its pieces at one ti
me,
strtok() gets pieces (called tokens) from a string one a
t a time.
$token = strtok($feedback, "@ );
---------------------------------------------------------------------------------------strcmp() - strcmp($a,$b)
---------------------------------------------------------------------------------------strcasecmp() - The function strcasecmp() is identical except that it is not case
sensitive.
---------------------------------------------------------------------------------------strnatcmp()
non case sensitive twin, strnatcasecmp()
strlen()

---------------------------------------------------------------------------------------strstr() . ?> otp: jay Ullal ---------------------------------------------------------------------------------------strchr() $a="Ajay Ullal". 5). except. echo strpos($test. ---------------------------------------------------------------------------------------stristr() .The second variant is strrchr(). This code echoes the value 7 to the browser because PHP has started looking for the character o at position 5 and therefore does not see the one at position 4. which is nearly identical but is not case sensitive. which is again nearly identical."ja"). otherwise. if (strstr($feedback. . The functions strpos() and strrpos() operate in a similar fashion to strstr(). $b=strchr($a. <?php $a="Ajay Ullal". it returns false. out : ay Ullal ---------------------------------------------------------------------------------------strrchr() . strrpos() The strrpos() function is almost identical but returns the position of the last occurrence of the needle in the haystack. ---------------------------------------------------------------------------------------ucfirst() .The function strstr().Capitalizes first character of string web site if it s alphabetic. the function returns the haystack from the needle onward. instead of returning a substring. which is the most generic. can be used to find a string or character match within a longer string. they return the numerical position of a needle within a haystack. If an exact match of the needle is found.stristr(). echo $b. shop )) You pass the function a haystack to be searched and a needle to be found. $b=strstr($a. o . ---------------------------------------------------------------------------------------strpos $test = "Hello world". echo $b."a"). bu t returns the haystack from the last occurrence of the needle onward.

ucwords() . $feedback = str_replace("fuck". int &count])) . ---------------------------------------------------------------------------------------******** Regular Expression Pending . you should reformat them with addslashes() a s follows: $feedback = addslashes(trim($_POST['feedback'])). substr_replace string substr_replace(string string. stripslashes() removes the slashes.Whi ch part is replaced depends on the values of the start and optional length paramete rs. mixed haystack[. stripslashes() . int [length] ). ---------------------------------------------------------------------------------------str_replace : mixed str_replace(mixed needle. int start. $feedback). addslashes() -Before you write any strings into a database. %!@* . string replacement. all the quotation marks have been slashed out. they might contain " \ other characters that wont be interpreted by the php interpreter properly so ad dslashes() is use). This function replaces part of the string string with the string replacement.Capitalizes first character of each word in the string that begins with an alphabetic character ****(Used when A form data is sent to php for validation.After the addslashes() function is called. mixed new_needle.