Tuesday, June 27, 2006

bye bye BlogSpot

I have decided to stop writing any technical entries here . but now I have one blog contains my personal and technical blogs . you can visit it here -> http://shref1.spaces.msn.com

c ya

Thursday, April 20, 2006

simple XML in php5

In php5 there is a new simple way to process or create XML files , It's the SimpleXML
It's not the powerful or the best but it's the simplest and the best choice for working with simple xml files like RSS.

here I will show you how you can read a RSS feed in simple steps with SimpleXML

first, we will start a new Object that's takes the path of the XML file, we will read the arabic bbc news feed so we will use this url ( http://newsrss.bbc.co.uk/rss/arabic/news/rss.xml )

CODE

$xml = simple_xml_file( 'http://newsrss.bbc.co.uk/rss/arabic/news/rss.xml' ) ;

so now we have the file loaded into a new Object called $xml

then we will loop through the file to get the values of the targeted elements

CODE

foreach ($xml->item as $news)
{
echo
$news->title . '
\n\r
'
;
}


there is simpler than that ?!

Monday, March 13, 2006

Story : Performance Phobia

I was working days ago on a web site requires some multi-sorting operations and other big operations in the same page . i didn't sleep well for three days, not because it's hard to be done, but because of the performance .
i have a very crazy storys running in my head about other developers who was murdered by their clients because of the bad performance in their applications ... lol , i really got a - performance phobia - (you can imagine me setting there shivering and looking left and right with the sound of britney's song "crazy" in the background ->[Monk2]).

After suffering of that thoughts for days, i found my self ready to start the scarry part (testing the application).
Oh my God, my brain telling me to be ready for a huge explosion. okay, I went to my IDE and started testing .

-> what is that??!!
every thing is working well and there is no slow operations or high load and the big surprise is that there is no crazy men coming with guns and shooting at me .. lol
i know that there is other guys setting there and saying "hay buddy, test it on a server with 1000 requests min. and tell us the number of server explosions/second".
yes, i did that and it worked fine too after some optimizations .

but why I'm telling you that story ?!
just to know that there is inner fears that's just lives in our minds only .

so Imagine the best, plan what you want to do, know your challenges and don't allow that stupid fears to stop you.

that's not only relates to programming and programmers, but relates to all the branches of your life.
so try to live better .


happy programming .... and happy life.

Monday, January 30, 2006

php as a templating system

some php programmers used to use templating systems like Smarty, phpbb templates or XTemplate to separate the php codes (the logic) from HTML (the view) .

but php itself is a templating language , so using another templating language with it is a waste of this feature in php.

so there is some projects trying to reclaim php to use it as a good templating system such like ( Savant and SimpleT )

i like Savant and you will find many samples and plugins on it's web site.

but why i have to use something like Savant to do the same work ?!!
just as this will improve the performance of your application.

in the other templating systems :
1- the code of the templating system will be compiled by the php interpreter on run time .
2- the templating system will compile the templates .

but with something like Savant you will have one cycle of compilations as we are using php itself for control statments and place holders.

so, are you going to use your templating system again?!! ;)

Tuesday, November 22, 2005

Highlight my Code

I think you have seen many web sites highlighting their codes like this


<?php

include 'me.php';

//my name

$name = 'ahmed';

print $name;

?>


that's not a big problem when we can use some builte-in php functions like highlight_string .
this function highlights php codes only, but what can i do to highlight codes from other languages like C#, C++, Java ...etc.
i have found some tools can help you to work this out like GeSHi and pear::Text_Highlighter
this two classes have the ability to highlight what ever you want of codes in simple steps.

GeSHi have a big number of already supported languages so i don't have to create it by myself again. Also i can add my custom language support like its sister in pear.
IMO GeSHi is faster and better as your languages information stored in php files but with Text_Highlighter you will add this information in XML files.
think about the used memory resources to read this file (big file) and the time of execution.
may i'm wrong but i will leave you to test it your self.

Saturday, November 19, 2005

play with SQLite

i was searching for any thing not very famous to play with, now i'm setting with SQLite.
it's the new supported database engine in php5.

SQlite has many features that's can make it better than many other database engines , but you can't use it everywhere.

IMO it's good but using MySQL is better till now.
just i wanted to push you to test it.

bye

Wednesday, September 28, 2005

MySQL 5 & stored procedures

hi all,
did you know that the first MySQL 5.0 Release Candidate is Available now ?!!
yes, that's right and you can get it from here.

i have recived the MySQL news letter 2 hours ago and iam so happy to see MySQL in a new style with its new features to be powerful enough to start the long way with Oracle, MS SQL and DB2 .
may we have to wait another 3 years to see MySQL side by side with its competitors .

but let's see the most useful features in that release:
1- stored procedures (i like it so much)
2- triggers
3- views
4- information schema (i was in need of that)
5- Archive storage engine

iam not a databases expert but i know the benefits of using the stored procedures in my applications and i want to thank tarik ibrahim as he was the first one who explained it to me .

in a little words : stored procedures are as same as the normal functions in php or c/c++ but it's stored in the database.
Ex.
CREATE PROCEDURE get_data(IN var1 INTEGER)
BEGIN
IF var1 >= 5 THEN
SELECT * FROM users WHERE id = var1;
ELSE
SELECT * FROM admin WHERE id = var1;
END IF;
END

maybe it's not clear for some people but reading it again will make it familier to you and very simple.

let's see what we can do with php:
Ex.
$userID = 2 ;

$result = mysql_query( 'call get_data(' . $userID . ')' );

there is more advanced ways to use stored procedures and many many reasons to make it your first choice.
check dev.mysql.com for more and be ready to get the finished release soon.