Reading blog feed using PHP

Web programming
Well, once I made the last post about how to read a blog feed in ASP.Net using LINQ I just wondered if I would be able to do it in PHP too, so I did it. Here's the code: [sourcecode language="php" wraplines="false"] function getBlogFeed($urlRSS) { $doc = new DOMDocument(); $doc->load($urlRSS); $arrFeeds = array(); foreach ($doc->getElementsByTagName('item') as $node): $itemRSS = array ( 'title' => $node->getElementsByTagName('title')->item(0)->nodeValue, 'desc' => $node->getElementsByTagName('description')->item(0)->nodeValue, 'link' => $node->getElementsByTagName('link')->item(0)->nodeValue, 'date' => $node->getElementsByTagName('pubDate')->item(0)->nodeValue ); array_push($arrFeeds, $itemRSS); endforeach; return $arrFeeds; } [/sourcecode] Once you have that done you can just show it as you wish, this is my show function but have in mind it uses my css styles (you can have a look at how it looks at my home page). [sourcecode language="php" wraplines="false"] function showBlogFeed($urlRSS){ if ($urlRSS !== ''):…
Read More

Reading blog feed in Atom or RSS with LINQ

Web programming
One of the most practical features a blog has its the possibility of requesting the latest posts from another webpage to read it without the need of accessing its current webpage. For doing this crazy idea blogs use XML technology, the REST protocol and one of the syndication standards like RSS, RSS2.0, Atom or RDF. In this case I am going to use RSS2.0 to request the feed of my blog and I will manage it with Linq so that I will have a collection of my latest posts in a few lines. Let's see the code: [sourcecode language="vb" wraplines="false"] Private Sub readBlogRSS20() Dim feed As XDocument = XDocument.Load("http://www.rubencanton.com/blog/feed/") Dim sum = From item In feed.Element("rss").Element("channel").Elements("item") _ Select New BlogArticle(item.Element("title"), item.Element("link"), _ item.Element("pubDate"), item.Element("description")) End Sub [/sourcecode] I just load…
Read More

Birth, life and death of XHTML

Web standards
Before XHTML was the egg, no no, the chicken, well ok it was HTML 4.01. HTML was good, flexible, practical, allowed developers to do many things (and to not closing them), and despite its shortcomings we were happy, web developers used the font tag to apply styles and web browsers interpreted what they wanted. But then a new technology arrived, XML, allowing to create your own markup language, which means that you can create your own HTML (HTML is a programming language that works with labels, so that if I put a text between the labels <b> and </b> it will appear in bold). With XML you could make your own and custom HTML, with the tags that pleased you, you might even have HTML in Spanish! <negrita>esto está en…
Read More

Extension methods in C#.Net

Web programming
One very useful thing we have in .Net technology is the possibility of extending it's classes to have our own and useful methods to work with. For example, imagine I need to show the user name in the project saying hello, something like this: "Hello Ruben!". But, I do not know if the name is stored in the database in lowercase, uppercase or how. So, I am going to capitalize it to be sure: [sourcecode language="csharp" wraplines="false"] public void SayHello() { string userName = "ruben"; Console.WriteLine(userName.Capitalize()); } [/sourcecode] But, Oops! We have a problem. The method Capitalize does not exist in C# string class, so we cannot just capitalize it with an instruction and we are going to need to make a library which we'll have to call always to…
Read More

Readonly vs Const in C#.Net

Web programming
In C#.Net we have two ways to establish a value that is constant (which means that its value will not be modifiable). The first way is the old one, making a const variable (maybe you know it as #define), the second one is to make a readonly variable. The most important difference between them is that a const will be evaluated at compile time while a readonly variable will be evaluated at run time. This limits the possibilities with consts since you cannot, for example, declare const structures, as they will need to call a constructor and that has to be made in run time, but you still can attach some expressions to it as soon as it can be resolved in compilation time. [sourcecode language="csharp" wraplines="false"] public const int…
Read More

Using LINQ in VB.Net for selecting encoded data

Web programming
Between the multiple advantages which offers LINQ I think there's the possibility of reselect some data you have in cache or RAM so you don't need to send another request to the database. I was programming a little personal application in VB.Net yesterday and found myself with a little problem. I am saving some data encoded in base64 in the database and I want to have the option to filter and show only the ones which match. The problem came when I realized that, of course, having the data encoded in the Access DB I couldn't just use a "LIKE" to filter the selection, since the characters are not as they really are. First of all I thought on decoding the data in the DB and then filter but I…
Read More

Content relevance. Let’s use some colors

Web design, Web usability
This is a translation from my original post in spanish. I hope you like it! We are planning a new design for our website and doubt between using blue, red, pink, yellow, ... What would be better? What if I put bright pink edges? Surely no one would forget my web ... All the ones who have built a website once have gone through this process. What color to choose? Why can't I just put fluorescent orange background? Well, some things seem obvious, but others less so. I will try to order some ideas on this issue in this post. When designing a website, the first thing you have to think about is what is it's objective, from that point, try to steer the user towards this goal. For example,…
Read More

Asynchronous request with JavaScript: home-made AJAX

Web programming
This is a translation from my original post in spanish. I hope you enjoy it! Note: Original post had code in HTML, sorry if I missed something. A few days ago I was building a module that should make asynchronous requests to a webservice using javascript, in other words, the famous AJAX but manually made, without using any library. For those who do not know what AJAX is, it's what allows server requests without having to load the entire page. Surely you've seen it in many places, for example, when posting a comment on a blog which is posted and shown without a full reload of the page. So, in order to do this we need to use the XMLHttpRequest object of our browser using JavaScript and send a request…
Read More

Testing LINQ performance with ASP.Net

Web programming
This post its a translation from my original post in spanish. I hope you enjoy it! :) After learning the basics about LINQ and how it works, I had no choice but to test if, not only does it simplifies the code but also improves its efficiency. I decided to test the reading speed of XML files with LINQ and determine which one has a better reading speed: .Net XML access library or its new technology, LINQ. To that purpose, I built an XML with 100.000 registers which simulates a table with students data and I will send some requests. (more…)
Read More

How to throw a pop-up properly with Javascript

Web programming, Web standards
This is a translation from my original post in spanish. Hope you enjoy it! In some cases it can be useful for us and even more comfortable for the user to open a page in a pop-up on which to show the information. If we search in Google how to do it or read any javascript manual the code that will be shown its this one: [sourcecode language="js" wraplines="false"] window.open('url to open','window name','attribute1,attribute2') [/sourcecode] In fact, that code has some mistakes, lets see: Browsers without Javascript will cannot open the page. It will not be crawled correctly by searchers, and some crawlers, will not know how to follow it. When going over it with the mouse we will not see the url on our browser status bar. The user loses…
Read More

Design consistency

Web design, Web usability
In general, design consistency its about avoiding the user having to think at all times how to do what he wants to, and for that purpose the best way its to make things appear always in the same way, so once learned how the site works, learned forever. Consistency with other websites This is one of usability foundations, if your niche websites place a triangle shaped button where it says "Go to checkout" and you decide that this button will be a square and say "Order", possibly the user will lose a couple of seconds looking for the triangle button he is accustomed to. If users have become accustomed to something through other websites of your niche, copy those "standards" and make life easier for the user. Example: The RSS…
Read More

How to make a wordpress widget

Web programming
This is a translation from my original post in spanish. I hope you enjoy it! :) Continuing with the make your own wordpress theme guide, it is possible that you come to the point where you need a new module you don't have in the sidebar, more known as widget. There are a few ways for doing this, in one side since you can choose between a dynamic and an static sidebar you could choose the second one and just develop it in php in one piece, though it will not be editable from the administration panel. Another option is to enter in the admin panel and create a text widget which you can use to insert javascript or HTML code. But the problem comes in case you want to…
Read More

Hello World!

Other
This is the first post on this blog I'm just releasing today, same day as my 27th birthday. I hope it will be as successful as it's Spanish older brother entrecodigos.com (betweencodes.com). I'm gonna translate some of my Spanish blog old posts to this one during the next weeks. I hope you enjoy them as much as I did!
Read More