Grab URLs from a String in PHP


Found this little Regex pattern which is an improved version of Daring Fireball’s (found here). Throw whatever string of various mixed up URLs you can at it, and this will return an array of them.

[code lang="php"]
$regexp = '/\b((?:[a-z][\w-]+:(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:(?:[^\s()<>.]+[.]?)+|\((?:[^\s()<>]+|(?:\([^\s()<>]+\)))*\))+(?:\((?:[^\s()<>]+|(?:\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:\'".,<>?«»“”‘’]))/i';

preg_match_all($regexp, $message, $matches);

return $matches[0];
[/code]

Overriding Form Theme of a Collection (Symfony2)


This code was floating around in a pastebin, and was linked to me from IRC. I’m not sure who originally wrote it, but it’s useful and I wanted to make sure it gets saved so that it can eventually be the basis of a Symfony2 cookbook article.

[code lang="php"]{% block collection_widget %}
{% spaceless %}
<div class="collection">
{% if prototype is defined %}
{% set attr = attr|merge({'data-prototype': block('collection_item_widget') }) %}
{% endif %}
<div {{ block('widget_container_attributes') }}>
{{ form_errors(form) }}
<ul>
{% for rows in form %}
<li>
{% set fieldNum = 1 %}
{% for row in rows %}
<div class="field{{ fieldNum }}">
{{ form_label(row) }}
{{ form_widget(row, { 'attr': { 'class': 'test' }}) }}
</div>
{% set fieldNum = fieldNum + 1 %}
{% endfor %}
<a class="remove" title="Remove" href="javascript:void()">
<span>Delete</span>
</a>
<div class="clear"></div>
</li>
{% endfor %}
</ul>
{{ form_rest(form) }}
</div>
<div class="clear"></div>
<a class="add" title="Add" href="javascript:void()">
<div style="display: none;"></div>
<span>Add</span>
</a>
</div>
<div class="clear"></div>
{% endspaceless %}
{% endblock collection_widget %}

{% block collection_item_widget %}
{% spaceless %}
<li>
{% set fieldNum = 1 %}
{% for row in prototype %}
<div class="field{{ fieldNum }}">
{{ form_label(row) }}
{{ form_widget(row, { 'attr': { 'class': 'test' }}) }}
</div>
{% set fieldNum = fieldNum + 1 %}
{% endfor %}
<a class="remove" title="Remove" href="javascript:void()">
<span>Delete</span>
</a>
<div class="clear"></div>
</li>
{% endspaceless %}
{% endblock collection_item_widget %}[/code]

Also, here’s a github gist link to the same code.

Facebook Simple Like: A No-Mess Facebook Fan Page Like Button [WP Plugin]


Want to boost your Facebook fan page subscription rate? This WordPress plugin makes what should be an easy task, but isn’t, an easy one. It enables you to use a shortcode to place a small like button where ever you like without the ordinary clutter: stream, faces, count, and all of the other junk that comes with the “fan page like box” ordinarily. Basically, it generates a fan page subscription button that looks *identical* to the one ordinarily only for *sharing* a page (as opposed to actually subscribing).

Download Now

 

Installation Instructions
All you need to do is unzip it in your wp-content/plugins folder and then activate it in the wp-admin area of your blog.

Like this plugin? Want to contribute?
If you like this plugin there’s a few different ways you can contribute.

 

Screenshots!

 

The Facebook fan page like button with the default white (#FFFFFF) iframe background (generated with the shortcode), contrasting with the ordinary look of the Facebook "like box."

The settings/configuration page for Facebook Simple Like.

The profile pictures section of your facebook fan page, which is where you find the requisite "profile id" of your fan page.

 

Adding Files via a Custom Meta Box In WordPress


From wordpress 3.0 version wordpress introduced the custom_post_type function. Many people want to attach the file field with add_meta_box function. In this tutorial I will tell you how to upload file with custom meta box and post type.

In this tutorial I will show you how to create the custom post type and add custom meta boxes to that post type and upload file with custom meta box.

See full tutorial at: File upload with add_meta_box or custom_post_type in wordpress

I am now a PHP 5.3 Zend Certified Engineer


I'm a PHP 5.3 Zend Certified Engineer!

I have to admit, I am a bit pleased with myself. I’m usually not the bragging type, I swear.

However, if any of you follow some of my previous blog posts you might recall my mentioning that I had bought the Zend PHP 5.3 certification exam. I gave myself a relatively short timeline to study for it (~2 weeks) and take it, and for the most part just studied the PHP.net manual focusing in on what was mentioned in the study guide, as well as those blurbs I mentioned in my previous post that I’d run across (which mostly just re-iterated what was said in the free study guide on Zend’s site).

I have played around with PHP for a number of years, but not really ever sat down and focused on the fundamentals like I knew I should have, so putting a little cash on the line helped me really push myself on this.

I used a spaced repetition program called Anki, on my iphone, to memorize the syntax to a lot of the common functions in PHP. If you haven’t heard of Anki before, make sure to check it out. It seems like one of the best techniques a person could leverage to really grow fluency in any language — whether programming or otherwise, short of just constant application.

So what’s next? Hmm… I could take a shot at Zend framework (which I would need to learn from scratch), but… Instead, I have to admit I’m eying some of Oracle’s MySQL certifications with envy. Like PHP itself, I have some previous experience and can use this as an opportunity to again focus down on the fundamentals.

Also, here’s a really cool tidbit: the official MySQL certification study guide comes with a 25% off voucher for the test itself, essentially making the study guide… free!
Continue reading

Zend PHP 5.3 Certification: Exam Purchased.


I made the purchase. I’ve been thinking about doing this for a while. I already know a little bit about PHP from having dabbled in it for a while, but have remained otherwise fairly mediocre with it. My logic is kind of like that of a gym membership: if you shovel out the cash to get one, you’ll probably make a point to show up at some point.

In this case, it gives me some motivation to get some broader aspects coded in my brain for the test. I’ve made a few useful things in PHP strictly for my own uses, but found it previously challenging to make much headway in a reasonable amount of time. Hopefully this should speed the process up by the time I’m done with it, and I happen to get a license for the PHP IDE Zend Studio, and a nice little certificate to go with it.

I managed to run across a few blurbs from people who have actually taken the test on what to focus on. Here’s one from an amazon review of php|Architect’s study guide:

Want to pass the exam? Know the following things:

1. What can and can’t go in a function/variable name.

2. What typehints are, how they work, and where they’re applied.

3. What all of the array_*() functions do. The more verbose array_*_*() functions which nobody uses can be safely skipped over.

4. How to use the SimpleXML library in a very general way i.e. access elements, attributes and convert to DOM.

5. Everything about the new object model, including abstract and final classes, the new constructor format, destructors, autoloaders and access specifiers (public, private, protected).

6. How and when to pass by reference.

7. When things go out of scope.

8. What the following php.ini directives do: allow_url_fopen, register_globals, enable_dl, disable_functions.

9. What goes in the superglobals and when ($_SERVER, $_GET, $_POST, $_REQUEST, $_ARGV).

10. What all of the bitwise operators do (you should also be able to convert numbers to and from decimal, octal, hexadecimal and binary notation with nothing but your brain and a piece of scratch paper).

Database topics are covered, but you generally don’t have to know any of the nonsense about mysqli or PDO–these things are all too buggy to actually use anyway, so learning about them is doubly pointless. If you can memorize function argument lists, do so with the preg_ and various string functions, because they like to throw some curveballs that use the optional args no one ever thinks about. If you can’t, then don’t bother because you can usually eliminate at least two of the choices they give you right off the bat and guess your way through the rest.

I found a few other pieces of advice at stackoverflow as well:

Areas of Focus: The main thing to focus on (ridiculous I know) are array and string functions. Believe it or not, a large portion of the exam will test you on knowing which functions do what and even what order the parameters are passed (this is particularly annoying because even among related functions, parameter order is not consistent). Also be aware of the functionality added to PHP 5 (SPL, PDO, object-oriented code, and the new XML functionality with SimpleXML and DOMDocument).

Assuming I dominate this test like I plan to, I might take a shot at one of the Oracle SQL certifications… but I may be getting ahead of myself. Wish me luck.

Oh, I forgot to mention. Part of this “experiment” is that I’m making a killer stack of Anki flash cards. So, in theory, if I continue to use Anki even after passing the test, I should be able to keep a near perfect recall of all of the information I’ve learned. For the uninitiated, Anki is a spaced repetition program much like Mnemosyne, but with the exception that it has a convenient iphone app available.

[AMAZONPRODUCT=0672327090]