Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

string function in php

<?php
    $x = 'Hello';
    print "Length of string is: " . strlen($x);
    print "<br>Count of word: " . str_word_count($x);
    print "<br>Reverse the string: " . strrev($x);
    print "<br>Position of string: " . strpos('Have a nice day!', 'nice');  //2 argument
    print "<br>String replace: " . str_replace('good', 'nice', 'have a good day!');  //3 argument
    print "<br>String convert to uppercase: " . strtoupper($x);
    print "<br>String convert to lowercase: " . strtolower($x);
    print "<br>convert first character into uppercase: " . ucfirst('good day');
    print "<br>convert first character into lowercase: " . lcfirst('Good noon');
    print "<br>convert first character of each word into uppercase: " . ucwords('keep going on!');
    print "<br>Remove space from left side: " . ltrim("        hi..");
    print "<br>Remove space from right side: " . rtrim("hello          ");
    print "<br>Remove both side of space: " . trim("       keep learning       ");
    print "<br>string encrypted with MD5: " . md5($x);
    print "<br>Compare both string: " . strcoll('Hello', 'Hello') . "<br>" . strcmp('kinjal', $x);
    print "<br>Return part of string: " . substr('Hello Everyone', 2);
    ?>
 
PREVIOUS NEXT
Tagged: #string #function #php
ADD COMMENT
Topic
Name
4+4 =