rss feed to html
Posted by chaabant on Jan 1, 2008
This post is about how to take rss feeds and convert it to HTML for display issues .
Note : This is a basic methods , but the aim of it could be for affiliate marketing , anyone could take this and convert it to an ebay store using his affiliate id .
Since the rss feed is always updated , the site will update it self .
so here is the source code for it :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
<?php $url = "http://www.chaaban.info/?feed=rss"; // url feed of my blog , it's just an wordpress xml file ... $xml = new SimpleXMLElement($url, null, true); foreach($xml->channel->item as $itm){ echo "<a href=\"$itm->link\"> $itm->title </a> "; echo "<br />"; } ?> |
<?php
$url = "http://www.chaaban.info/?feed=rss"; // url feed of my blog , it's just an wordpress xml file ...
$xml = new SimpleXMLElement($url, null, true);
foreach($xml->channel->item as $itm){
echo "<a href=\"$itm->link\"> $itm->title </a> ";
echo "<br />";
}
?>
Data Types in PHP
Posted by chaabant on Dec 28, 2007
Data Types in PHP
In php there is different types of data , the most used are :
string // binary data
boolean // true or false
int // Integer
Integers are numbers; Positive and negative numbers can be expressed with it).
Boolean contain two values: false or true .
String Are text , it could be also a collection of binary data (contents of a doc file or image or even mp3 file)
Declaring Variables in PHP
To declare variables in php all what you need to do is place a $ at the beginging of a name that you will give to your variable to refer it .
ex :
1 2 3 4 5 |
$my_number = 13 ; // declaring variable called my_number $my_name = "Chaaban"; // declaring a variable called "my_name" that contain : Chaaban ; $whatever = true ; // declaring a variable called "whatever" that contain a boolean value of true . |
$my_number = 13 ; // declaring variable called my_number $my_name = "Chaaban"; // declaring a variable called "my_name" that contain : Chaaban ; $whatever = true ; // declaring a variable called "whatever" that contain a boolean value of true .
php is different than other languages , you can declare a variable that contain a number and later replace it with a string or boolean .
ex :
1 2 3 4 5 6 7 8 9 |
$x = 10 ; // random codes // ... // random codes $x = "HELLO WORLD"; echo $x ; // will display : HELLO WORLD instead of 10 |
$x = 10 ; // random codes // ... // random codes $x = "HELLO WORLD"; echo $x ; // will display : HELLO WORLD instead of 10
Invalid names when Declaring a Variable
Variables must be named using only letters (a-z, A-Z), numbers and the underscore character; Their namesmust start with either a letter or an underscore, and are one of only two identifier types in PHP that are case sensitive
1 2 3 |
$txt = ’valid’ ; // valid $_txt = ’valid’; // Valid variable name $10txt = ’invalid’; // Invalid varianle name since it starts with a number |
$txt = ’valid’ ; // valid $_txt = ’valid’; // Valid variable name $10txt = ’invalid’; // Invalid varianle name since it starts with a number
How to put comments in php
Posted by chaabant on Dec 26, 2007
In php there are different ways to put comments , comments are very important .
Importance of php Comments in programming:
- It’s a Good Practice
- It saves a lot of time , you won’t need to read your code to understand what it does
- Make your code understandable for others, so that if many programmers are working on a same project, or when your boss fires you, it would be helpful for then next programmer to understand what you have done.
Any code that took thought to write will take thought to reread after several days, months or in some cases, years.
Ok , now let’s go back to How to put comments in php …
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
// Single line comment # Single line comment /* Multi-line Line 1 Line 2 Line 3 */ /** * API Documentation Example * * @param string $bar */ function foo($bar) { } //code |
// Single line comment
# Single line comment
/* Multi-line
Line 1
Line 2
Line 3
*/
/**
* API Documentation Example
*
* @param string $bar
*/
function foo($bar) { } //code
Hello world in php
Posted by chaabant on Dec 26, 2007
Those are some ways to make a Hello world in php
Hello world in php using Variables
Hello world in php using Functions
1 2 3 4 5 6 7 8 9 10 |
<? function hello () { echo " Hello World !! "; } hello(); ?> |
<?
function hello () {
echo " Hello World !! ";
}
hello();
?>
Welcome to Tutorials 4 PHP
Posted by chaabant on Mar 25, 2006
Welcome to Tutorials 4 PHP .
This site is still under construction ,I will start from A to Z in php .
Hope this project will help the Web Community understand how php works . I have other projects that will run with this project , like tutorials for html and tutorials for javascript .
If you have any question , use the contact form at the top of the page .
Good Luck .
Tarek .