It’s a common problem with no single right answer: extract the top domain (e.g. example.com) from a given string, which may or may not be a valid URL. I had need of such functionality recently and found answers around the web lacking. So if you ever “just wanted the domain name” out of a string, [...]
Read MorePosts tagged "php"
Get HTTP status code of cURL call in PHP
With all the fancy cURL-based API’s out there these days (Facebook and Twitter immediately come to mind), using cURL to directly access and manipulate data is becoming quite common. However like all programming, there’s always the chance for an error to occur, and thus these calls must be immediately followed by error checks to ensure [...]
Read More browsers, php, software development, TwitterBuild a slick Twitter feed on your site
A few months ago I published an article describing how to output a Twitter stream on a page using PHP, and later followed up with two more to polish the display. The article content and code examples have since been tweaked based on feedback and my own debugging. If you haven’t already had a look, [...]
Read More lifestream, php, programming, regular expressions, social networking, TwitterTranslating PHP error constants
I wanted to log all the errors thrown out by Fwd:Vault processes to ensure that any bugs I don’t catch myself bubble to the top very quickly. To get started, I replaced PHP’s default error handling with a custom error handler function, which simply logs the error in a MySQL table before passing it along [...]
Read More fwdvault, php, software developmentCircumvent PHP errors with define_once()
Core PHP does not include a define_once() function to complement functions like require_once() and include_once(), which is pretty silly in my opinion. While I am generally not a fan of using *_once statements due to the performance penalty (and incurred laziness), define_once is the exception. There are ways to look for a loaded/missing file, but [...]
Read More coding theory, handy functions, phpFind the second (or third, or fourth) occurence in a string
PHP includes some handy functions to find the first or last occurrence of a given string token in a string: strpos and strrpos. However these functions are limited to just the first occurrence; what if I want to know the location of the second token’s position, or the third? These problems usually result in some [...]
Read More handy functions, php, programmingExtract email addresses from tags
Ran into another cool hurdle today for my Fwd:Vault development. When I grab the message content to archive it in the system, first thing I do is scrub it out to ensure that (a) it displays properly, and (b) there are no misbehaving characters. I grab both plain text and HTML email formats (if present), [...]
Read More email, fwdvault, php, programming, regular expressions, security, usabilityParse URL’s in text, create links
I’m absolutely in love with the status update stream I’ve put together for Fwd:Vault (follow link for example). However in the process, I’ve discovered a huge drawback to the Twitter messaging system: it does not store links. The Twitter site itself will identify URL’s in messages and convert them into clickable links for you automatically. [...]
Read More fwdvault, php, regular expressions, TwitterDisplay Twitter updates on your website
Update: I’ve added a new chunk of code that will download and store your Twitter posts in a database, allowing you to do whatever the heck you want with them. After you’ve finished reading this, be sure to check that out as well. I am not a fan of social networking or so-called lifestreaming. I [...]
Read More extension, fwdvault, php, TwitterGet number of message parts in an email using PHP
Alright, I admit up front that this is a pretty specific problem, but hopefully some Googlers will find it useful. I recently had need for a small side project to read e-mails. Every e-mail is split up into parts; each “part” represents every separate piece of the e-mail. The plain text format, rich text or [...]
Read More email, php, software development- 1
- 2