Twitter
LinkedIn
RSS
Facebook
ClickBank1

Archive for the Coding Category


Cool preg_replace Solution

A two-dimensional array stored as a one-dimens...

The situation: Read a product description from a product database.

The problem: The block of text for the product description in the comma delimited file is not formatted, and in fact looks stripped of whatever formatting it had previously. Chunks of text squished together like “changes.Special” (no space after the period), and “Disc BrakeHeadset” (obviously missing a space between Brake and Headset).

I surmised that the missing spaces were previously line breaks (\n or <br>). If a scan/replace function had been used and the line break characters replaced with a null value, it would fit the puzzle perfectly.

Read More...

PHP/MYSQL String Tricks

Here’s a couple things I always forget. I’m adding them here so I’ll have them for future reference.

How to “Scan and Replace” a String in MYSQL

(Note the AS400-ish wording of that title).

Big Note: Be very careful of serialized data!!!!

Thanks to http://www.mydigitallife.info/how-to-find-and-replace-text-in-mysql-database-using-sql/ for these little pieces of code.

The syntax of REPLACE is REPLACE(text_string, from_string, to_string)

Like this:

update TABLE_NAME set FIELD_NAME = replace(FIELD_NAME, ‘find this string’, ‘replace found string with this string’);

update wp_posts set post_content = replace(post_content, ‘http://domain.com/blog/’, ‘http://domain.com/’)

The above statement will replace all instances of ‘http://domain.com/blog’ to ‘http://domain.com/’ in the field of post_content of wp_posts table.

Read More...

Free Format RPG ILE Alternatives to the TIME Opcode

Time me

Here’s one of the free format BIFs I can never remember as far as syntax is concerned. Maybe if I keep it here I will be able to find it again :) . I copied some of this from http://www.bmeyers.net/faqs/frequently-asked-questions/41-free-format-alternatives-to-time (the Q&A part).

Q. In fixed format RPG IV, I used the TIME operation code to get the current date and time; but TIME is not supported by free format. You mentioned that the %DATE, %TIME, and %TIMESTAMP functions can replace TIME, but I’m not sure how to use them for this purpose.

In my programs, I create a data structure like this:

Read More...