Eval For Inline PHP Inside HTML

Eval is real cool and can give a lot more versatility to a coder. Eval for PHP has a small functionality issue one beginner would not expect. If you eval, the parameter has to be a PHP code string. But if you have HTML and inline PHP code, there's a catch.

eval("<b>cool <?=' stuff'?></b>");

If you try to eval the above it will fail as it's not PHP code. It's HTML with PHP inside. And, as eval evaluates the expression as if it was executed in the place where it's called, this eval will never work. On the other hand this will work:

eval("echo 'stuff';");

This can be evaled easily no matter what. It's only PHP code, the whole point of EVAL.
Read the rest of this entry »

A Better PHP GZDecode Function

As most of you know I had a very popular GZDecode version on my old blog. But, it was not really as good as it looked like. I found the problems when I was trying to expand a monthly GZEncoded raw access log. I realized it was a file made of many welded GZEncoded entities each on its own. So my way of expanding did not work.
Read the rest of this entry »

RSScraping | Scraping RSS With PHP, DOM and XPath Magic

I wrote a post on some XPath magic for all you evil scrapers out there. Now I will show you how to scrape RSS feeds. I used to do it the RegExp way but now I decided to head over to XML parsing and DOM processing. Lazy enough I decided to look for an already made version and found a quite good one actually. Close to my needs but not exactly. I took it, used and abused the source (ended up changing almost completely), and achieved the one I needed. The good thing about the RSS Scraper using DOM XML + PHP is that it's way shorter and much more reliable than the RegExp version.
Read the rest of this entry »

Output Buffering | Complex Inline HTML | Wordpress Plugin Writers

I wanted a simple method to handle some output buffering when coding plugins. Let's take this situation. You want to alter the_content filter but you want to make the modifications inline.

To manage inline HTML in PHP you got two options: regular string ... impossible. HEREDOCs ... not good for complex PHP code. So you are left with regular ?>HTML + PHP<?php. But returning this as a variable is not trivial. You need to output buffer it by using ob_start(); ... HTML + PHP code ... $html = ob_get_contents(); ob_end_clean();. And this will allow you to wrap inside a variable any kind of complex HTML code thanks to super output buffering in PHP.
Read the rest of this entry »

elHttpClient Evolution - PHP + cURL + HTTP

My mildly wildly popular eHttpClient class no longer available on my old blog has evolved. It changed into elHttpClient, an all new toy for the fellow blackhats and php coders. eHttpClient is the one-stop solution for web downloading combining the power of cURL with PHP to provide a dead easy solution for your web downloading (scraping) needs.With basic knowledge you can do anything in terms of downloading web content.

This class has been by far my most popular share and brought in most feedback. I've looked into the feedback trying to make things even easier and this was born. Oh wtf ... the truth is I've written this for myself and decided to share it! I didn't care about no feedback.
Read the rest of this entry »