Tag Archives: php

As Usual

As usual, it is been a hell of a long time since I have had time to write something here. This year has flown by… lost a job, lost a loved one, business idea failed, got a 6-month contract; it came and went, went to E3, went to a concert (Coheed and Cambria), flew in a private jet, endured “the Armpit of America”, went to IndieCade and turned 25 somewhere in between. I am sure a lot more happened in between but my point is; it has been interesting, sad, fun and quite a blur.

So I said my 6-month contract “came and went” but I left out the fact that they decided to hire me full-time. Apparently I know what I am doing, or something like that. It has been pretty interesting because after October 1st we began tapering off active development on the “legacy” platform (osCommerce). So since then I have been doing some follow-up development on minor bugs and whatnot and other than that I have been working on learning C#, SharePoint and Microsoft CRM.

It has been pretty cool being able (see having some time) to read up on and prototype some code / projects with C#. On top of that being able to integrate the C# development into web parts on the SharePoint server. I’ve been trying to spend as much time as possible working with it, but it is still busy at work. We have been working pretty closely with the consultants to help wherever we can to get this project launch ready for next year. I have been doing some front-end work, data exports and manipulation, etc; some of it tedious but it’s understood its for the greater good.

On another note, the year is nearly over. I did not realize that the next 4 weekends I am going to be either gone or busy. This Thursday night, my buddy Tylar and I are leaving for Las Vegas for MineCon for the weekend (maybe we’ll even write an article or two about it on VGVee). Next weekend is Turkey Day (Thanksgiving in the US) weekend and the following weekend Cindy and I are going to be leaving for Hawaii for a week. Guess I planned everything pretty well, haha…

It is very possible that this will be the last post for the year, unless I find something I need to write about before then. So, if that is the case, have a great holiday season and happy new year. I’ll be the drunk guy drinking, as usual.

Work and Life

Work has been pretty great so far, 2 weeks in and still surviving. One major thing that has been a bit of a twist is the dress code change; suit and tie is quite a bit different than jeans and a polo. Though, I have been skimping on the tie as much as possible, I am a rebel. The work environment is good though, everyone seems pretty welcoming, even though I am the “temp” -which is apparently a term that does not bode well with me, but I am what I am at this point, I guess.

So I have been working and improving on the existing code for the site and I am going to just go ahead and say it… osCommerce has to be the worst thing I have ever developed on top of, not to mentioned how hacked together the whole system is, i.e. talking to the back-end ERP system. At the end of the day, it is functioning, but it is basically at its limit for what it can do without spending hours of development time to add new features. Basically, I can see why they want to ditch this shit and move to a more proprietary platform.

I am at a bit of an impasse with the work at times because after a couple days of looking at the code I realized working with osCommerce has no plus side for me. I do not learn anything and I sometimes want to kick my own teeth out. Maybe I should place some blame on the former developers as well, some of the hacks they put in place are just irritating. But, my goal is to fix this pile of shit while they transition and I will take my down time and do more prototyping with C# so that in a few months I may be an asset for them in regards to the new system.

On a non-work related note, I have been pretty much relaxing after work, it’s draining, I told you. I started watching 24 again from the first season, it is enjoyable. Something exciting and cool is that my brother and I picked up a new site from Flippa yesterday, we are in the escrow process, currently waiting for the transfer on the server to us, already have the domains. This has been a quick and smooth transaction thus far and I am very pleased with the process and the seller.

We are ready to revamp the site and take it to the next level, we are hoping that at a minimum to keep the existing income but obviously if we can increase it, that is ideal. The current income does not cover all the server expenses so the possibility of a loss exists. I am working with my current provider to possibly transition the site to their system, where the current income level would make it a wash.

Time to crunch the numbers and figure out the best plan of attack!

Reading HTML with PHP and XPath

Learning new things is fun, especially when you get paid to learn said new thing! A couple months ago I was tasked with scraping data from a website, as a proof of concept of course. I thought it was going to take me forever, trying to use regular expressions to find certain strings in the data, trial and error, you know what I mean. Well, I found out that through PHP’s SimpleXMLElement your can use a function called XPath to query the DOM you have loaded.

Normally, xpath is used for reading nodes within the DOM of an XML document, but you can trick PHP into reading non-well-formatted HTML; awesome right? Here is a quick example how to get this working:

$sampleContent = '<html>
	<head>
	<title>Sample Content</title>
	</head>
	<body>
	<a href="mailto:test@testing.com">Email Me!</a>
	</body>
	</html>';

//Disable libxml errors and allow user to
//fetch error information as needed
libxml_use_internal_errors(true);

$dom = new DOMDocument();

$dom->loadHTML($sampleContent);

$xpath = new DOMXPath($dom);

//find the email
$result = $xpath->query('//a[contains(@href, "mailto:")]/@href');
$email = $result->item(0)->nodeValue;

//we need to strip out the mailto: portion
$email = preg_replace('/mailto:/', '', $email);

echo $email;

This is the first step to being able to read the data within your HTML document. One thing I found that made it easier to query and find the data you are looking for is by installing XPath Checker for FireFox. Now only if there was a comparable version for Chrome.

In the very distant future (like in the next couple of days), I will expand upon this article to detail from start to finish how to utilize cURL and XPath to successfully scrape data from a website.