Thursday, September 5, 2013

STRING FUNCTIONS (PART-1)

Example: 1


<?php

//strlen();
//mb_substr();
//explode();
//implode(); or  join();
//nl2br();
//strrev();
//strtolower();
//strtoupper();
//substr_count();
//substr_replace();

?>



Example: 2


<?php

//strlen();
//mb_substr();
//explode();
//implode(); or  join();
//nl2br();
//strrev();
//strtolower();
//strtoupper();
//substr_count();
//substr_replace();


//strlen();

$string ="Hellow";
echo strlen($string);


?>



Example 3


<?php

//strlen();
//mb_substr();
//explode();
//implode(); or  join();
//nl2br();
//strrev();
//strtolower();
//strtoupper();
//substr_count();
//substr_replace();


//mb_substr();

$string ="My name is alex.";
echo mb_substr($string,0,2);


?>



Example 4


<?php

//strlen();
//mb_substr();
//explode();
//implode(); or  join();
//nl2br();
//strrev();
//strtolower();
//strtoupper();
//substr_count();
//substr_replace();



//mb_substr();

$string ="My name is alex.";
$length = strlen($string);
echo mb_substr($string,0,$length);

?>



Example 5


<?php

//strlen();
//mb_substr();
//explode();
//implode(); or  join();
//nl2br();
//strrev();
//strtolower();
//strtoupper();
//substr_count();
//substr_replace();

//mb_substr();

$string ="My name is alex.";
$length = strlen($string);
echo mb_substr($string,0,$length-5);


?>


Example 6


<?php

//strlen();
//mb_substr();
//explode();
//implode(); or  join();
//nl2br();
//strrev();
//strtolower();
//strtoupper();
//substr_count();
//substr_replace();



//explode();

$string ="1 2 3 4 5";
echo explode("",$string);

?>


Example 7


<?php

//strlen();
//mb_substr();
//explode();
//implode(); or  join();
//nl2br();
//strrev();
//strtolower();
//strtoupper();
//substr_count();
//substr_replace();



//explode();

$string ="1 2 3 4 5";
$exparray = explode("",$string);
echo explode[1];

?>


Example 8


<?php

//strlen();
//mb_substr();
//explode();
//implode(); or  join();
//nl2br();
//strrev();
//strtolower();
//strtoupper();
//substr_count();
//substr_replace();



//explode();

$string ="1/2/3/4/5";
$exparray = explode("/",$string);
echo explode[1];

?>


Example 9


<?php

//strlen();
//mb_substr();
//explode();
//implode(); or  join();
//nl2br();
//strrev();
//strtolower();
//strtoupper();
//substr_count();
//substr_replace();


//implode(); or  join();

$string ="1/2/3/4/5";
$exparray = explode("/",$string);

$newstring = implode($exparray);

?>


Example 10


<?php

//strlen();
//mb_substr();
//explode();
//implode(); or  join();
//nl2br();
//strrev();
//strtolower();
//strtoupper();
//substr_count();
//substr_replace();



//implode(); or  join();

$string ="1/2/3/4/5";
$exparray = explode("/",$string);

$newstring = implode($exparray);
echo $newstring;

?>



Example 11


<?php

//strlen();
//mb_substr();
//explode();
//implode(); or  join();
//nl2br();
//strrev();
//strtolower();
//strtoupper();
//substr_count();
//substr_replace();



//implode(); or  join();

$string ="1/2/3/4/5";
$exparray = explode("/",$string);

$newstring = implode($exparray, "/>");
echo $newstring;


?>


Example 12



<?php

//strlen();
//mb_substr();
//explode();
//implode(); or  join();
//nl2br();
//strrev();
//strtolower();
//strtoupper();
//substr_count();
//substr_replace();



//implode(); or  join();

$string ="1/2/3/4/5";
$exparray = explode("/",$string);

$newstring = join($exparray, "/");
echo $newstring;


?>


Example 13



<?php

//strlen();
//mb_substr();
//explode();
//implode(); or  join();
//nl2br();
//strrev();
//strtolower();
//strtoupper();
//substr_count();
//substr_replace();


//nl2br();

echo "
Hellow
New line
Another New Line
";

?>


Example 14


<?php

//strlen();
//mb_substr();
//explode();
//implode(); or  join();
//nl2br();
//strrev();
//strtolower();
//strtoupper();
//substr_count();
//substr_replace();


//nl2br();

echo "
Hellow
New line
Another New Line
";

?>


Example 15


<?php

//strlen();
//mb_substr();
//explode();
//implode(); or  join();
//nl2br();
//strrev();
//strtolower();
//strtoupper();
//substr_count();
//substr_replace();


//nl2br();

echo "
Hellow <br>
New line <br>
Another New Line
";

?>


Example 16


<?php

//strlen();
//mb_substr();
//explode();
//implode(); or  join();
//nl2br();
//strrev();
//strtolower();
//strtoupper();
//substr_count();
//substr_replace();


//nl2br();

echo nl2br("Hellow
New line
Another New Line
");

?>

1 comment:

Unknown said...

easy to understand for beginners