skip to main |
skip to sidebar
RSS Feeds
Technical interview questions for software engineers — languages, databases, cloud, DevOps, and CS fundamentals.
Technical interview questions for software engineers — languages, databases, cloud, DevOps, and CS fundamentals.
Technical interview questions for software engineers — languages, databases, web, cloud, DevOps, and fundamentals. Browse all topics.
Posted by Raj
<?php
// Mysql Connection
$conn = mysql_connect('localhost','root','');
if (!$conn) {
die('Could not connect to MySQL: ' . mysql_error());
}
echo 'Connection OK'; mysql_close($conn);
// Select Database
mysql_select_db("test");
// Array of the Month's
$month_array=array("jan","Feb","Mar","Apr","May","Jun","july",'Aug',"Sep","Oct","Nov","Dec");
// Array of the Years's
$year_array=array("2013","2014");
foreach($year_array as $year)
{
foreach($month_array as $month)
{
echo $second=date('Y-m-d', strtotime("second sat of $month $year"));
echo "<br>";
echo $fourth=date('Y-m-d', strtotime("fourth sat of $month $year"));
echo "<br>";
}
}
?>
Posted by Raj
<?php
/*
Example: Yahoo! Weather API Example Using SimpleXML in PHP.
The base URL for the Weather RSS feed is
http://weather.yahooapis.com/forecastrss
Parameters
w WOEID
e.g: w=111111
u Units for temperature
f: Fahrenheit
c: Celsius
e.g.: u=c
*/
$city="bangalore";
$result1 = file_get_contents("http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20geo.places%20where%20text%3D%22$city%22&format=xml");
$xml1 = simplexml_load_string($result1);
$woeid=$xml1->results->place->woeid;
if($woeid!="")
{
$fetchData = file_get_contents("http://weather.yahooapis.com/forecastrss?w=$woeid&u=c");
$xmlData = simplexml_load_string($fetchData);
$location = $xmlData->channel->xpath('yweather:location');
if(!empty($location))
{
foreach($xmlData->channel->item as $data)
{
$current_condition = $data->xpath('yweather:condition');
$forecast = $data->xpath('yweather:forecast');
$current_condition = $current_condition[0];
echo "
<table width=40% border=1 align=center>
<tr>
<td align=center style='background-color:yellow'>
<h1>{$location[0]['city']}, {$location[0]['region']}</h1>
<small>Date: {$current_condition['date']}</small>
<h2>Current Temprature</h2>
<p>
<span style=\"font-size:64px;font-color:red; font-weight:bold;\">{$current_condition['temp']}°C</span>
<br/>
<img src=\"http://l.yimg.com/a/i/us/we/52/{$current_condition['code']}.gif\" style=\"vertical-align: middle;\"/>
{$current_condition['text']}
</p>
<h2>Forecast</h2>
<b>{$forecast[0]['day']}</b> : {$forecast[0]['text']}. <b>High:</b> {$forecast[0]['high']} <b>Low:</b> {$forecast[0]['low']}
<br/>
<b>{$forecast[1]['day']}</b> - {$forecast[1]['text']}. <b>High:</b> {$forecast[1]['high']} <b>Low:</b> {$forecast[1]['low']}
</p>
</td>
</tr></table>
";
}
}
else
{
echo "<h1>please try a different City.</h1>";
}
}
else
{
echo "<h1>Please try a different City.</h1>";
}
?>
Posted by Raj
<?php
$hrs= array( "0" => 11, "1" => 12 ,"2" => 13 ,"3" => 14 ,"4" => 15);
$data= array ("0" => 15 ,"1" => 11, "2" => 5, "3" => 15 ,"4" => 17 );
$hrs_len=sizeof($hrs);
if(!empty($data) && !empty($hrs))
{
$data=array_combine($hrs,$data);
$image_width=($hrs_len+1)*32;
$image_height=80;
$padding=20;
$graph_width=$image_width - $padding * 2;
$graph_height=$image_height - $padding * 2;
$image=imagecreate($image_width,$image_height);
$bar_width=25;
$total_bars=count($data);
$gap= 5;
$background_color=imagecolorallocate($image,255,255,255);
$border_color=imagecolorallocate($image,255,255,255);
$line_color=imagecolorallocate($image,255,255,255);
$max_value=max($data);
$ratio= $graph_height/$max_value;
$horizontal_data=20;
$horizontal_gap=$graph_height/$horizontal_data;
for($i=1;$i<=$horizontal_data;$i++){
$y=$image_height - $padding - $horizontal_gap * $i ;
imageline($image,$padding,$y,$image_width-$padding,$y,$line_color);
$v=intval($horizontal_gap * $i /$ratio);
}
$bar_color=imagecolorallocate($image,50,205,50);
for($i=0;$i< $total_bars; $i++){
list($key,$value)=each($data);
$x1= $padding + $gap + $i * ($gap+$bar_width) ;
$x2= $x1 + $bar_width;
$y1=$padding +$graph_height- intval($value * $ratio) ;
$y2=$image_height-$padding;
imagestring($image,0,$x1+3,$y1-10,$value,$bar_color);
imagestring($image,0,$x1+3,$image_height-15,$key,$bar_color);
imagefilledrectangle($image,$x1,$y1,$x2,$y2,$bar_color);
}
header("Content-type:image/png");
imagepng($image);
}
?>
Posted by Raj
<?php
ini_set("display_errors",1);
error_reporting(E_ERROR);
$msg="&command=1";
$url = "http://127.0.0.1:1234";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $msg);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($curl);
if($response!="")
{
$fp = fopen("test.txt","w");
fwrite( $fp, $response);
fclose($fp);
}
curl_close($curl);
?>
Posted by Raj
<!DOCTYPE html>
<HTML lang="en"><HEAD>
<TITLE>Print Visitor card using PHP/JavaScript </TITLE>
<META content=IE=7 http-equiv=X-UA-Compatible>
<META content="text/html; charset=Windows-1252" http-equiv=Content-Type>
<STYLE>
#outer
{
border-collapse:collapse;
border: 0px solid black;
height:250px;width:420px;
}
.cover{
background:#EEEEEE;
padding: 10px;
text-align:left;
margin:10px;
width:400px;
height:200px;
font-size: 1.0em;
top:10%; left:10%;
/*--CSS3 Box Shadows--*/
-webkit-box-shadow: 0px 0px 20px #000;
-moz-box-shadow: 0px 0px 20px #000;
box-shadow: 0px 0px 20px #000;
/*--CSS3 Rounded Corners--*/
-webkit-border-radius: 30px;
-moz-border-radius: 30px;
border-radius: 30px;
}
#inner
{
border-collapse:collapse;
border: 0px solid black;
height:100%;width:100%;
background:#EEEEEE;
}
#hgt_abv
{ height:18%;}
#hgt_abv_back
{ float:inherit;
height:18px;
width:400px;
background:#000000;
}
#hgt_belo
{ height:3%;background:#FF6600;}
.docimg
{
float:inherit;
hight:119px;
width:90px;
}
.logo
{
float:left;
width:100px;
}
.address
{
padding:2px;
text-align:left;
margin:2px;
hight:100px;
width:130px;
font-size: 1.1em;
}
</STYLE>
<META name=GENERATOR content="MSHTML 9.00.8112.16446"></HEAD>
<BODY class="ExtravaganzaAqua page-view2" >
<CENTER><SPAN></SPAN>
<TABLE id=outer>
<TR>
<TD><DIV class=cover>
<TABLE id=inner border=0>
<TR>
<TD align=center colspan="2">
<DIV id=hgt_abv_back><FONT color=#ffffff size=3><B>VISITOR PASS</B></FONT></DIV>
</TD>
</TR>
<TR>
<TD valign="top" align=left><br /><FONT size=2><B>Name: </B><B>Computer Geek</B><br /><br /><br />
<B>Designation: </B><B>Software Engg.</B><br /><br /><br />
<B>Date: </B><B>24th Nov 2012</B><br />
</FONT>
</TD>
<TD valign="top" align=right>
<img width="90" hight="119px" src="user.jpg" alt="bg">
</TD>
</TR>
<TR id=hgt_belo>
<TD colSpan=2></TD>
</TR>
</TABLE>
</DIV>
</TD>
</TR>
</TABLE>
</CENTER>
<center>
<table id=outer>
<tr>
<td align="right" valign="top">
<button type="button" onclick="window.print();" >Print</button>
</td>
</tr>
</table>
</center>
</BODY>
</HTML>
Posted by Raj
Posted by Raj
Posted by Raj
Posted by Raj
Posted by Raj
Posted by Raj
Posted by Raj
Posted by Raj
Posted by Raj
Posted by Raj
Posted by Raj
Posted by Raj
Posted by Raj
Posted by Raj
Posted by Raj