Here is the example of the string function in PHP.
$text = "The string function";
$THEwordTHATyouWANTtoCHANGEit = "string";
$REPLACEthatWORDwithTHIS = "strong";
print $text . "<BR>";
$text = str_replace($THEwordTHATyouWANTtoCHANGEit,
$REPLACEthatWORDwithTHIS , $text);
print $text;
str_word_count()
$number_words = str_word_count("how many word?");
print $number_words;
strlen()
$length_of_string = strlen("This is how to count the length of string");
-note:it count the character and the space in the string.
substr()
$username = "my name is dotcom";
$check = substr($username, strlen($username) - 6);
if ($check == "dotcom" ) {
print "ends in dotcom";
}
else {
print "doesn't end in dotcom";
-note:strlen($username)-6 :PHP will take six character because we put(-6), if -4 then it take 4 character that behind this string.So,our string is this :my name is dotcom,then PHP will start to count at red,bold 'm' as one until six.So sixth charatcer is:d . Then,$check is equal to 'dotcom'.
N/NOTE:selamat mencuba!!!
No comments:
Post a Comment