Showing posts with label string functions in php. Show all posts
Showing posts with label string functions in php. Show all posts

Sunday, December 4, 2011

String Functions

Code Example


example.html
<html>
    <body>
        <form action="example.php">
            Enter a string <input type="text" name="string" value="" /><br/>
            <input type="submit" value="   Submit    " name="submit"/>
        </form>
    </body>
</html>
example.php
<?php
 if(isset ($_GET['submit'])){
     $string = $_GET['string'];
     //encrypt the string
     echo 'encrypt the string : '.  crypt($string).'<br/>';

     // lenth of th string  
     echo 'lenth of the string : '.  strlen($string).'<br/>';  

     // possition of a string
     echo 'possition of a in string : '.  strpos($string, 'a').'<br/>';

     //capitalize the first character
     echo 'uper case first char : '.  ucfirst($string).'<br/>';
 }
?>

explode() method

Code Example

split() method is deprecated in php 5.3. Instead of split()  use explode().

explode.php

<?php
$text= "hello friends how are you?";
$newtext= explode(' ', $text);
foreach ($newtext as $str){
    echo $str.'<br/>';
}
?>
output:
hello
friends
how
are
you?