unknown os platform
Free Beginner PHP Tutorials - String inbuilt functions | Whats-online.info
whats-online-info

Free Beginner PHP Tutorials - String inbuilt functions


Free
2016:09:30 / Science and Tutorials

PHP internal (in-built) functions. string length, reverse string, shuffle string, string position, string replace and string position in PHP





PHP: Internal (built-in) functions


PHP inbuilt functions are predefined functions that are called within a program to execute. This functions can be called anywhere within the program. Don't require the declaration keyword '$global' to get them included in user-defined functions.

Some of the PHP inbuilt functions are:

1.strlen();
2.str_word_count(); 
3.strrev();
4.strpos();
5.str_replace();

and much more

PHP strlen()

Returns the length of a string 

syntax

<?php     strlen("String size"); ?>

example

<?php     echo strlen("String size"); ?>

output: 11
The above example returns the length of the string 'String Size'


PHP str_word_count()

Counts the number of words in a sentence

syntax

<?php str_word_count("Words number"); ?>

example

<?php echo str_word_count("Hello there"); ?>

Output: 2
The above example returns the number of words in a sentence or paragraph

PHP strrev()

reverses a string

syntax

<?php strrev("Reverse String"); ?>

example

<?php echo strrev("Hello there"); ?>

output: ereht olleH
The above example reverses a string.

PHP strpos()

Searches for a particular text in a string and the function returns the character position of the first match if a match is found otherwise return FALSE.

syntax

<?php strpos("Search string position","searched"); ?>

example

<?php echo strpos("Hello sir  there","there"); ?>

output: 11

The above example searches for the string 'there' and returns the position of the first character 't'

PHP str_replace()

This function replaces some characters with some other characters in a string.

syntax

<?php str_replace("search","replace","string"); ?>

example

<?php echo str_replace("there","here","hello there"); ?>

output: hello here
The above example searches for the string there and replaces it with the string here.











You may also like:


Leave a comment












Subscribe to get replies direct to your mailbox

Submit comment