Geeks On PHP OOP Update

I want to give everybody a quick update on what is going on with Geeks On PHP and what to expect in the near future. As we talked about on our last episode we are putting together a series of podcasts focused on OOP in PHP. Unfortunately due to time constraints, work overload and other things out of our control we have had to push things back a bit. The series is still going to happen and we are excited to have Mitchell Hislop who is a friend of mine and a very talented developer / social media expert joining us for the series.

As soon as we are able to settle on dates to record I will provide updates via Twitter and our Facebook page letting people know what to expect. Thank you for your patience and we look forward to releasing a great series on OOP!

Follow both Stephen & Myself on Twitter and also subscribe via Tunes.

- Nicholas

  • Share/Bookmark

Read Users' Comments (2)

Geeks On PHP Episode 13

This week Stephen and I talk about strings and how they are accessed, manipulated and used in PHP.

We kick off the discussion talking about some differences between echo() and printf(). Below is an example of using both functions to populate a text field on a web form. We will start off with using echo():


.. input type="text" name="foo" id="foo"
[Inside PHP Block]
if(!empty($dbresult['foo']))
echo ' value="'.$dbresult['foo'].'" />';
else
echo ' value="" />';
?>

Here is the same end-result using printf():


... input type="text" name="foo" id="foo"
[Inside PHP Block]
printf(" value=\"%s\" ", !empty($dbresult['foo']) ? $aResults['foo'] : "");
?>

I tried to make the “argument” during the show that printf() allows for a lot more flexibility as well as resulting in slightly more compact code. Notice the usage of PHP’s ternary operator in the printf() example. It allows for a great deal of flexibility and power directly in-line w/ your output statement.

Regular Expressions were also a big topic of discussion this week and as promised here are some examples of commonly used RegEx’s in web application development:


$pattern_date = '#(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)\d\d#';
$pattern_email = '#^[a-zA-Z._]+@[a-zA-Z_]+?\.[a-zA-Z]{2,4}$#';
$pattern_email2 = '#^\w+([\.%-]\w+)*@\w+([\.-]\w+)*(\.\w{2,})+$#';
$pattern_phone = '#^(?:\([2-9]\d{2}\)\ ?|[2-9]\d{2}(?:\-?|\ ?))[2-9]\d{2}[- ]?\d{4}$#';
$pattern_time = '#(1[0-2]|[1-9]):([0-5][0-9])#';
$pattern_url = '#(http|https)\://[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,4}(/\S*)?$#';
$pattern_alphanum = "#^[a-zA-Z0-9\s]+$#";

To test matching on these patterns you can simply use the preg_match() function:

preg_match($pattern, $string, $matches);
if(!empty($matches))
    print_r($matches);

A couple of my favorite resources for regular expressions are:
The Online Regular Expression Testing Tool
The Regular Expression Library

Regular Expressions provide so much power and versatility when it comes to pattern matching and replacements that they just can’t be ignored. If you have questions about any of the above please let us know.

Follow both Stephen and Myself on Twitter and also subscribe via Tunes!

Enjoy the show and as always, stay geeky!

Audio clip: Adobe Flash Player (version 9 or above) is required to play this audio clip. Download the latest version here. You also need to have JavaScript enabled in your browser.

- Nicholas

  • Share/Bookmark

Read Users' Comments (1)

Geeks On PHP Episode 10

We are happy to bring you episode 10 of the Geeks On PHP Podcast!  This week we talk about API programming, specific API’s that we have worked with, some great development tips and even alcohol.  This episode has it all.

The Authorize.net API comes up a bit in discussion and I mention the article I wrote a couple of days ago regarding some changes to online debt card processing as it pertains to the Authorize.net API.

We invite you to follow both Stephen and I on Twitter and also subscribe to us on iTunes!

Enjoy the show and as always, stay geeky!

Audio clip: Adobe Flash Player (version 9 or above) is required to play this audio clip. Download the latest version here. You also need to have JavaScript enabled in your browser.

- Nicholas

  • Share/Bookmark

Read Users' Comments (0)

New MasterCard & Discover Processing Requirements

MasterCard and Discover are modifying their rules concerning processing of debit, prepaid and gift cards. MasterCard’s rule changes went into effect 5/1/2010 and Discover’s rule changes went into effect on 4/16/2010. Merchants using Authorize.Net have until 6/30/2011 to comply with the new standards but since I am compliance hound I wanted to make these changes immediately.

Since I was reading up on all of the documentation and re-working my API code accordingly I figured I would share the changes with everyone in hopes of saving people a bit of time when they sit down to modify their own code.

So what’s new?
– Balance response transactions
– Partial authorization transactions
– Authorization reversals

So what does all that mean?
Transactions made on a gift/debt/etc card can now be split among multiple cards using partial authorization and the splitTenderId value. This value “links” the authorization request to subsequent transactions.

The new API request fields to pay attention to are ['x_allow_partial_Auth'] which is either true or false and ['x_split_tender_id'] which gets set to the original authorization request value.

The new relay response reply fields are as follows:
['x_account_number'] = last 4 digits of card
['x_card_type'] = string value indicating the type of card used
['x_split_tender_id'] = original authorization value
['x_prepaid_requested_amount'] = amount requested in original auto
['x_prepaid_balance_on_card'] = balance on the debit/prepaid card

The obvious things to note here (aside from the tender id) are the card balance and the requested amount. With these two values you can easily determine if the transaction can go through or if a subsequent transaction (w/ the sane tender id) has been requested.

New response codes to take note of are the following:
Reason: 295 Code: 4 — Amount was only partially approved
Reason: 296 Code: 3 — The splitTenderId is invalid.
Reason: 297 Code: 3 — A trans ID and a Split Tender ID can’t both be used in a single transaction request.
Reason: 298 Code: 3 — The splitTenderId has been completed (released or voided) and can not be associated with new transactions.

Here is what a sample relay repines looks like: (Taken from official documentation)

Hopefully this summary helps identify the changes that need to be made and why. All of this information can be found in the official documentation which is available at: http://www.authorize.net/support/pafaqs/

- Nicholas

  • Share/Bookmark

Read Users' Comments (1)

Essential tools for PHP development

b1nary

As sort of a “follow-up” to my post from last week I am here to bring you what I think is a very solid list of tools for developing web applications with PHP.

1) Editor: TextMate (Mac Only), I really love this editor. On the PC I use PsPad.

2) Debug: A combination of writing robust error reporting in software, Firebug & Web Developer (firefox plug-ins) and apache weblog parsing

3) Tools: jQuery is my favorite toy right now, I am doing a lot of neat stuff with it and really bringing some database driven web applications “to life.”

4) Framework: CodeIgniter is a great, lightweight MVC (Model-View-Controller) framework for rapid PHP development.

5) Cross-browser testing: Honestly, I just use live machines.. I have heard very mixed things about Browsershots and haven’t looked into the other options. We just test all our stuff on multiple platforms/browsers to ensure compatibility across the board.

- Nicholas

  • Share/Bookmark

Read Users' Comments (0)

Essential browser plugins for web application developement

The topic of browser extensions and web application development has come up a bit lately so here is a short list of my “mission critical” extensions pertaining to developing/debugging web applications:

Firebug (Debugging / Monitoring)

FirePHP (Enables logging of Firebug Console using a simple PHP method call)

HTML Validator (Exactly what it sounds like, integrates nicely to firefox status bar)

Web Developer (CSS/DOM/HTML/JavaScript tools)

- Nicholas

  • Share/Bookmark

Read Users' Comments (0)

Easy & Dynamic Keyword Highlighting With PHP

Say you are fetching news article data from a database and want to “highilight” (or in this example make bold) specific keywords in the article abstract. Once we have our news article data we need to fetch our keyword data which can also come from a database (recommended) or it could be stored locally in an array.


while($array = pg_fetch_assoc($result))
{
  while($array_key = pg_fetch_assoc($result_key))
  {
    foreach($akeywords as $sphrase)
      $sbody = str_replace($sphrase, "<strong>" . $sphrase . "< /strong >", $soverview);
  }
  pg_result_seek($result_key, 0);
}

Assuming $akeywords is your array of keywords and $sbody is the body of text you want to “highlight”. For each keyword you have the body of text is parsed and if a match is found, a starting <strong> tag is added before the keyword and a closing </strong> tag is added after.

This is a very simple piece of code but it can really come in handy in a number of projects.

- Nicholas

  • Share/Bookmark

Read Users' Comments (0)