String Functions

Check Function

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″ />
<title>Untitled Document</title>
</head>

<body>
<center>
<?php
$directory = new Directory(‘.’);
var_dump(method_exists($directory,’read’));

var_dump(function_exists(“phpinfo”));
var_dump(function_exists(“function_exists”));
?>
</center>
</body>
</html>

 

Head Function

<?php
print ‘Redirecting…<br>’;

echo “hello you will be redirected in few seconds”;
header(“Refresh:5 ; URL=checkfun.php”);

?>

 

Html Entities

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
<title>Untitled Document</title>
</head>

<body>
<?php
$htmlen = “<script language = \”javascript\”>while (true){ alert (\”This code will not be executed\”); break;}</script>”;

echo “without htmlentitites it will give alert”;
echo $htmlen;
echo “<br/><br/><br/>”;
echo “With htmlentities it will escape all the html entities in the variable and print the code intact<br/>”;
echo htmlentities($htmlen);
?>

</body>
</html>

 

String Function

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
<title>string functions using php</title>
</head>

<body>
<center>
<h1> String Functions in PHP </h1>
<br />
Example 1 <br />
<?php
$str = ” Hello World! “;
echo “Without trim: ” . $str;
echo “<br />”;
echo “With trim: ” . trim($str); //just look at the view source in browser.
?><hr />
<br />
Example 2 <br />

<?php
$str = “\r\nHello World!\r\n”;
echo “Without trim: ” . $str;
echo “<br />”;
echo “With trim: ” . trim($str);
// same way ltrim and rtrim function will work.
?>
<hr />
nl2br () function.<br />
<?php
$nl2br = “Hello \n World”;

echo “Without nl2br : ” . $nl2br;

echo “<br / >”;

echo “With nl2br : ” . nl2br($nl2br);
?>
<br />
<hr />
String Upper and Lower Functions.
<br/><hr/>
<?php
$string = “hello how are you”;

echo strtoupper($string);
echo “<br/>”;

echo strtolower($string);
echo “<br/>”;
echo ucfirst($string);
echo “<br/>”;
echo ucwords($string);
echo “<br/><hr/>”;
?>

</center>
</body>
</html>

 

 

Share

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.