Thursday, June 14, 2012

Interview Questions -PHP

Hi All,


I'm sharing my experience which may help to PHP buddies.

1.First Question :

   function 1dolist() {
       $number = 5;
      echo  1doout($number);
   }
    function 1doout($n) {
        return $n;

     }

 
   1dolist();





All d Best ....Post  your Answer.

Thursday, February 10, 2011

Read Text file Using PHP

Please find the logic:
$file_handle = fopen("file.txt", "rb");
while (!feof($file_handle) ) {

$line_of_text = fgets($file_handle);

$parts = explode(' ', $line_of_text);
foreach ($parts as $keys){
if($keys != ''){
$query_data[] =$keys;
}else{
$query_data[] ="NULL";
}
}

echo $str = implode(',', $query_data);
?>

Thursday, February 3, 2011

Export to Excel Using PHP

Hi
Use the Code :
# file name for download Using Headers
$filename = "urfile_data_" . date('Ymd') . ".xls";
header("Content-Disposition: attachment; filename=\"$filename\"");
header("Content-Type: application/vnd.ms-excel");

$flag = false;
$result = mysql_query($sql) or die('Query failed!');
while(false !== ($row = mysql_fetch_assoc($result))) {
if(!$flag) {
# display field/column names as first row
echo implode("\t", array_keys($row)) . "\n";
$flag = true;
}
array_walk($row, 'cleanData');
echo implode("\t", array_values($row)) . "\n";
}


function cleanData(&$str) {
$str = preg_replace("/\t/", "\\t", $str);
$str = preg_replace("/\r?\n/", "\\n", $str);
if(strstr($str, '"'))
$str = '"' . str_replace('"', '""', $str) . '"';
}

Friday, July 2, 2010

Passing Values from PHP to Javascript

Hi Developers,
We can able to send values from php to javascript using php coding without submit the form using submit button.
I think most of you are having knowledge to send values from php to javascript but i am posting for new buddies & myself

1)Create a New PHP page(sample.php) and Copy & Paste it.

echo "Hello ";
echo "
";
echo "Hello ";
echo "
";
echo "Hello ";
And ADD SCRIPT TAGS
function test(url) {
var chk = confirm ("Can i proceed?");
if(chk){
location.href=url;
}else{
alert('oooppppppppps');
}
}
Close SCRIPT TAGS.


2)Create a other New PHP page(test.php) and Copy & Paste it.

echo $_GET['id'];


Execute the code in the browser that php values are passed to javascript :)

Example Application:
Basic functionality for any appication in website i.e Delete a record in the database.


Gud Luck :)

Friday, June 25, 2010

Display a Triangle format Numbers using PHP code

Hi All,
Program to Display following using php code:
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15

CODE:
Start php here
$k=1;
for($i=0;$i<5;$i++){
for($j=0;$j<=$i;$j++){
echo $k." ";
$k++;
}
echo "
";
}
End php tag

Check out the output...


All d best

Thursday, June 24, 2010

CKEDITOR configuration to change Default settings

Hi All,
I need to modify a default setting in CKEDITOR for changing paragraph format in the editor to except "DIV" tags.
So i googled & worked on the configuration of CKEDITOR,finally i got a file i.e "ckeditor.js" located (ckeditor/ckeditor.js) and

Default Setting
enterMode:1
We need to modify
enterMode:3


Now check ur output i will set to "Normal(div)" format.


All d Best

Monday, June 14, 2010

Validation for Radio Button in Javascript

Hi Programmers,
I just faced little difficult to validate radio box element using java script but i think most of the developer had done lot of script on radio box validation.

For my sake i am posting blog on validation on radio box.

function valButton(btn) {
var cnt = -1;
for (var i=btn.length-1; i > -1; i--) {
if (btn[i].checked) {cnt = i; i = -1;}
}
if (cnt > -1) return btn[cnt].value;
else return null;
}

function valForm(form) {
var btn = valButton(form.group1);
if (btn == null) alert('No radio button selected');
else alert('Button value ' + btn + ' selected');
}