<?php
$sentence = "I lob to have tea but some time I prefer coffee";
//replacing tea from above sentence by milk with str_replace function
echo str_replace("tea","milk",$sentence);
?>
Tuesday, October 21, 2014
String function in php
Regular expression example 3
<?php
// type of regular expression
//posix style regular exrpession
//pcre style regular expression
$sentence = "I lob to have tea but some time I prefer coffee";
$regexp="love|lob|feelings";
// search the search the mentioned words in the sentence
if(ereg($regexp,$sentence))
{
echo "regular expression is true";
}
else
{
echo "regular expression is false";
}
?>
Regular expression example 2
<?php
// type of regular expression
//posix style regular exrpession
//pcre style regular expression
$sentence = "I lob to have tea but some time I prefer coffee";
//^ search the lob word in the begining of the sentence
if(ereg("^lob",$sentence))
{
echo "regular expression is true";
}
else
{
echo "regular expression is false";
}
?>
Regular expression example 1
<?php
// type of regular expression
//posix style regular exrpession
//pcre style regular expression
$sentence = "I lob to have tea but some time I prefer coffee";
if(ereg("lob",$sentence))
{
echo "regular expression is true";
}
else
{
echo "regular expression is false";
}
?>
Sunday, October 5, 2014
Get form data (get method)
1: <?php
2: $test = $_GET["test"];
3: $test2 = $_GET["test2"];
4: echo $test;
5: echo "</br>".$test2;
6: $len = strlen($test);
7: if($len > 0)
8: {
9: echo "</br>".$len + strlen($test2);
10: }
11: else
12: {
13: echo "error : there is no input";
14: }
15: ?>
16: <form method = "GET" action = "Basic3.php">
17: <input type= "text" name="test" >
18: <input type="text" name="test2">
19: <input type="submit" value="submit">
20: </form>
Posting form data (post method)
1: <?php
2: $temp = Array("one","two","cow","toe");
3: echo count($temp);
4: echo "</br>" . $temp[1];
5: for($i=0 ; $i < count($temp) ; $i++)
6: {
7: echo "</br>Loop #$i $temp[$i]" ;
8: }
9: $var =5;
10: if ($var == 4)
11: {
12: echo "value is 4";
13: }
14: elseif ($var == 5)
15: {
16: echo "value is 5";
17: }
18: ?>
Array
1: <?php
2: $temp = Array("one","two","cow","toe");
3: echo count($temp);
4: echo "</br>" . $temp[1];
5: for($i=0 ; $i < count($temp) ; $i++)
6: {
7: echo "</br>Loop #$i $temp[$i]" ;
8: }
9: $var =5;
10: if ($var == 4)
11: {
12: echo "value is 4";
13: }
14: elseif ($var == 5)
15: {
16: echo "value is 5";
17: }
18: ?>
Thursday, September 25, 2014
Declearing variables in php
<html>
<head>
<title>first php page</title>
</head>
<body>
hi there!<br>
<?php
//declearing variables
$myInteer = 5 ;
$myFloat = 55.63 ;
$myString = "Into the wild" ;
$todaysDate = date("m/d/y");
$firstName = "Dipen" ;
$lastName = "lama";
$Name = $firstName ." ". $lastName;
echo "Hey!<br>";
echo $firstName . " ". $lastName . "<br>";
echo $Name;
echo "The date was";
echo date("m/d/Y");
echo $todaysDate;
//echo "$myInteger + $myFloat=" .($myInteger + $myFloat) . "<br>" ;
echo "?";
?>
<br>
ok... i'm now not in a script.<br>
The time was<? echo date("h:i;s a");?><br>
Your IP address was:<? echo getenv("REMOTE_ADDR");?>
<body>
</html>
First basic php tutorial V2
<html>
<head>
<title>first php page</title>
</head>
<body>
hi there!<br>
<?php
echo "Dipen!<br>";
echo "The date was";
echo date("m/d/y");
echo"?";
?>
<br>
ok.... I'm now not in a script<br>
did you that the time was<? echo date("h:i:s a");?>
Your IP address was:<? echo getenv("REMOTE_ADDR");?>
<body>
</html>
First basic php tutorial
<html>
<head>
<title>Begining of basic 1st php page</title>
</head>
<body>
hi there!<br>
<?php
echo "Dipen!<br>";
echo "The date was";
echo date("m/d/y");
echo"?";
echo"<br> and current the time is". date("h:i:s");
?>
</body>
</html>
Subscribe to:
Posts (Atom)