PHP Tutorial : Create a RSS / XMLS Feed

Welcome,

In this tutorial I will show you how to create a basic rss / xml feed with php. Basically, if you know how to create a feed in notepad, wordpad or whatever text editor, this will be easy. The difference between creating a php xml / rss feed and a “normal” one it’s that you can do this feed dinamyc later, by extracting feed elements from a database such as MySQL.

<?php
$XMLoutput = "<?xml version=\"1.0\"?>
<rss version=\"2.0\">
<channel>
<title>PHP RSS XML FEED</title>
<link>http://www.exampledomain.com/RSS-XML-FEED.php</link>
<description>RSS Feed Description</description>
<language>en-us</language>
<pubDate>dd/mm/yy</pubDate>
<lastBuildDate>dd/mm/yy</lastBuildDate>
";
$XMLoutput .= " <item>
<title>A title here</title>
<link>Some link here</link>
<description>description goes here</description>
</item>";
$XMLoutput .= "</channel></rss>";
header("Content-Type: application/rss+xml");
print $XMLoutput;
?>
Posted in Usefull PHP | Tagged , , , , , , , , , , , , , | Leave a comment

PHP Tutorial : Forms processing with $_POST or $_GET

Are you just curious to know the difference between $_GET and $_POST php server variables? Errrr, let me try and explain. I dont see many differences, or maybe I dont know/explain, but what I understand it is that $_POST it’s used in most of the cases because security, and $_GET will show your entered forms fields values into the url. For example :

<form action="" method="POST">
Your field value here <input type="text" name="fieldname">
<input type="submit" name="sb" id="sb" value="Go">
</form>
<?php
//check if form was sent


if(isset($_POST['sb'])) {
print $_POST['fieldname'];
}
//this with post will not show values into url

?>
<form action="" method="GET">
Your field value here <input type="text" name="fieldname">
<input type="submit" name="sb" id="sb" value="Go">
</form>
As for get, you will see after you submit your form that value entered will showup in url
<?php

if(isset($_GET['sb'])) {
print $_GET['fieldname'];
}
//and check your url, if you make a forms.php page, and hit submit you'll see //forms.php?fieldname=whatyouentered&amp;sb=Go

?>
Posted in Basic PHP | Tagged , , , , , , , , , , | Leave a comment

PHP Tutorial : Clear white spaces

Ever got extra white spaces and dont wanna clear them manually or just cannot? In PHP, we have a great function called trim(), which will do your job. If you made a .htaccess rewrite (most of the cases), or just a form input to validate and clear its extra white spaces just do a trim().

<?php
$extraWhiteSpace = " bla bllla  b   l      a";
$extraWhiteSpace = trim($extraWhiteSpace);
?>
Posted in Basic PHP | Tagged , , , , , , , , | 2 Comments

PHP Tutorial : Lowercase characters

In a recent post I’ve been writed about converting string to uppercase, now we need to know how to convert characters into lowercase. That will need strtolower() function which means string to lower.

<?php
$bigger = "This Is Big";
$lower = strtolower($bigger);
//will print this is big

?>
Posted in Basic PHP | Tagged , , | Leave a comment

PHP Tutorial : Upper Case Characters

Another week, another fresh post over here. I will write shortly about two ways on how to make characters/letters upper case (capitalize). One way its strtoupper (string to upper) which converts all string, and the second its for first character only function ucfirst(). Here comes the example:

<?php
$capitalizeString = strtoupper("my string");
//will return MY STRING

$capitalizeFirst = ucfirst("my");
//returns My

?>
Posted in Short PHP Functions | Tagged , , , , , , , , | 2 Comments

It Stuff : How to add website url to google

Hello,
I am not sure if it’s related, or the next post you expected me to publish but I still find noobs asking for an elementary question like : how do I add my website url to google search engine? Well, you can do it via multiple ways like :
1) do some social bookmarking
2) get a high pagerank backlink (link to your site)
3) do some directory submissions
4) use some automated software (not recommended)
5) manually right here (it will take a time)

Do not expect to be on first page of google as soon as you submited your url to get crawled, thats other subject and hard seo work. Getting into google its simple, but getting into first page really needs dedicated work! But, the results will come and satisfaction should be big!

Posted in It Stuff | Tagged , , , , , | Leave a comment

PHP Tutorial : Block certain IP Address

I see this seems to be a very hot subject on the folks searching for php scripts and help. Its not really big deal to block a certain visitor IP Address. It works like : first you need to detect their IP, then you just send him a 404 not found header. Have a look:

<?php
$ip = $_SERVER['REMOTE_ADDR'];
$blocked = "127.0.0.1";

if($ip == $blocked) {
header("HTTP/1.0 404 Not Found");
exit();
}
?>
Posted in Usefull PHP | Tagged , , , , , , , , , , | 5 Comments

PHP Tutorial : Exit and Die Functions

hi,
I have two mins to write about those two very basic functions which will make your script to stop completely, the code will not be interpreted anymore before the line where says exit or die. have some tests (first one will exit without any notice and with the second one you can show a message to the browser before stoping the script)

<?php

print "something";
exit();

print "will not print";
//or like this which will show a message too
print "something else";
die("message");
?>
Posted in Short PHP Functions | Tagged , , , , , | Leave a comment

PHP Tutorial : Check PHP server configuration

Wow,
It’s aproximatively 2 months since I write on this php tutorials blog and I never writed about this premier function, very basic which I should show you in the very first two or three posts but I forgot about it : it is the function which checks php web server configuration : phpinfo(); How? Create a new file, and place it into your host, then access it and taddaaa – you’ll see and check php config (such as modules loaded, extensions, etc).

<?php
phpinfo();
?>
Posted in Basic PHP | Tagged , , , , , , , , | Leave a comment

PHP Tutorial : Implode function

Hi,
As I had issues with my old host, those days I worked to change it and didn’t had the time to post another nice php function called implode. This function php implode() simply joins the array elements into a string. Remember the explode function? Well this makes the reverse I would say in some way. Have a look :

<?php
$array = array("one", "two", "three");
$string = implode(",", $array);//make the "implosion"
print $string; //will return one, two, three
?>
Posted in Basic PHP | Tagged , , , , | 1 Comment