The wrong way to do string comparisons in the iPhone SDK
if(myTitle == @"HELLO")
The right way
if([myTilte isEqualToString:@"HELLO"])
The wrong way to do string comparisons in the iPhone SDK
if(myTitle == @"HELLO")
The right way
if([myTilte isEqualToString:@"HELLO"])
Dealing with trailing comas in lists is common problem for developers. I found the best way to handle this situation in PHP is with the following regular expression.
$string = eregi_replace(',$', '', $string);
Before: string = “2, 6, 9,”
After: string = “2, 6, 9”
Only the trailing coma will be stripped. If no coma is found, the string simply passes through. It’s a simple and effective solution.
Twitter is wildly popular and dominates the social media space. Penn State University recently conducted a study and found that 20% of all tweets (twitter updates) contain requests for product information or responses to the requests.
Twitter, with its six million active daily users (and predictions of more than 20 million users by the end of the year) is
“about as close as one can get to the customer point of purchase for products and services”
according to Jim Jansen, an associate professor in the College of Information Sciences and Technology (IST) at Penn State.
WordPress has the ability to allow post authors to assign custom fields to a post. This arbitrary extra information is known as meta-data. This meta-data can be used by theme authors to do some pretty cool things.
The theme I am currently using allows for a custom field named “thumb”. If you create the “thumb” custom field in a post and pass in the path to an image, for example “wp-content/uploads/2008/12/wordpress_logo.png”, a thumb nail version of the image will appear next the posts title on the home page of my blog. Awesome stuff.
When I discovered this theme and the “thumb” custom field, I already had 225 posts in my blog. I didn’t want to go back and manually create all the custom fields for the existing posts, so I wrote a PHP script to do it for me.
The PHP script cycles through your existing posts and looks for the first image in the post, and creates the thumb field based on it’s location. The script is configurable, your theme may want a different custom field name, like “thumbnail” or “image”.
This code is provided as is. If you aren’t a developer, you should be messing with stuff like this. Be sure to back up your wordpress database before running this.
Instruction:
Note: This is a one time deal, when you create new posts you will need to add the “thumb” field and image path manually
//your database configuration information
$username = "YOUR_USER_NAME";
$password = "YOUR_PASSWORD";
$database = "DATABASE";
$databaseLocation = "localhost";
//name of the Custom Field to use
$customFieldName = "thumb";
/******************* END CONFIGURATION *****************************/
//get the wordpress posts to work with
$query = "SELECT * FROM wp_posts";
if ($result = $mysqli->query("$query"))
{
//loop over all the posts
while ($row = $result->fetch_object())
{
//get all the info from the post that we need to work with
$cur_post_id = $row->ID;
$cur_post_content = $row->post_content;
//the pattern to find the html image tag
$pattern = '/]+src[\\s=\'"]';
$pattern .= '+([^"\'>\\s]+)/is';
//try to match the pattern against the post content
if(preg_match($pattern,$cur_post_content,$match))
{
//break up the image path
$pieces = explode("wp-content/", $match[1]);
//make sure the file name isnt empty
if($pieces[1] != "")
{
//build the file path
$imagePath = "wp-content/" . "$pieces[1]";
//insert the custom field for the post
$insertQuery = "INSERT INTO wp_postmeta (post_id, meta_key, meta_value) VALUES ($cur_post_id, '$customFieldName', '$imagePath')";
$mysqli->query("$insertQuery");
//debugging stuff
if ($mysqli->errno)
{
printf("failed: %s \n", $mysqli->error);
}
else
{
echo "..... inserting $imagePath \n";
}
flush();
}
}
}
}
echo "---completed---";
?>
Today AT&T unlocked MMS (multi media) messaging on the iPhone. Most of the world had had MMS messaging for YEARS now on their iPhone, but due to AT&T’s restrictions and fear of the data crushing their network they have limited the number of people that you can message at a single time to 10. This includes MMS and SMS (standard text messages)!
To most people, sending a single message to 10 people might be excessive, for me, it severely limiting. I am in charge of organizing activities for several organizations, social groups, and occasionally my church. The ability to send a single message to a large group of people has been so handy. Now if I need to send a txt message to 50 people, I’m going to have to send the same message 5 times. Talk about a step backwards!
Apple has also modified the messaging applications so you have to pick the phone number for the person you are trying to text, even if the contact only has one number. Before the MMS update, if only one phone number was in the contact, it would be used. The number of clicks has increased from 1 to 2. So, texting 10 people now requires 20 clicks instead of 10. Double the effort. I can’t see how this is progress. It feels like AT&T and Apple don’t want people to send as many text messages, so they are making it harder to do.
Dear AT&T thank you for giving up MMS messaging after all these year, but please give us back our mass texting abilities!