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');
}









Friday, May 28, 2010

Module Positons in Joomla in 1.0 and 1.5

How to create New positions in joomla:

Joomla 1.0.X version:

In joomla 1.0.X versions we will create the new module positions like this

go to site->template manager->module position

in that create new module position and save it by clicking the save button on the top right of the screen
Now your new module position is published.

then go to the content->section manager. create a new section by clicking the new button on the top right of the screen. and save it.

then go to the content->category manager. create a new category by clicking the new button on the top right of the screen. and save it.

For example i have created a section “test” and created a category “test”, then in order to create a content

go to content->content by section->test->test items

in that click the new button on the top right create the name of your content and section and category.

Then in the content area write these lines to publish your module in the desired page.

{mosloadposition MODULE}

this “MODULE “ is the position name you have created in moduleposition.

Go to module manager and select your module and give the position as “MODULE”

So that your module that was created by you or the installed module will be displayed in the desired page and location.

Joomla 1.5.X version:

In joomla 1.5.X versions we will create new module position like this

Install the module and copy the module by selecting the module and clicking the copy button on the top right corner of the screen.

then the copy module name will be "copy of module"

click on the "copy of module" change the module name and there is a column called position dropdown box will be there.

Generally we need to select the position from the dropdown box. But in this case it is an editable box even though it is a dropdown.

Give the name of the new position that should not be there in the dropdown. and enable it..

Now the new position name is let us say "MODULE"

i want to publish this module in my article page..

Go to the content->section manager. create a new section by clicking the new button on the top right of the screen. and save it.

then go to the content->category manager. create a new category by clicking the new button on the top right of the screen. and save it.

For eample i have created a section test and created a category test.then in order to go to content.

Go to Content->article manager. create a new article by clicking the new button on the top right corner of the screen.

give the name of the article and section and category.

write these lines where ever you want the module to be published on the page

{loadposition MODULE} MODULE is the name of the new module position.


Troubleshooting for joomla 1.5.X:


if the module is not shown on the desired page. check the plugin like this

Go to extensions->plugin manager. in that check whether Content - Load Module is published or not...,

If it is not published publish by clicking the 'x' mark in the enable column.

Once it is published then click on Content - Load Module. change the plug-in parameters.

In plug-in parameters there will be style dropdown..., click on the dropdown and select "No Wrapping(raw output)".

Blog by Satish M