LAMP How To – Open Source At Work

Only Passion Matters

Entries for the ‘Think PHP’ Category

simple function to truncate string to closest word

as the title implies… this is in wordpress though. preg_replace is the trick here.
function trim_excerpt() {
$text = get_the_excerpt();
$limit = 200;
if (strlen($text) > $limit) {
$text =  preg_replace(‘/\s+?(\S+)?$/’, ”, substr($text, 0, $limit)).’… ‘;
}
return $text;
}

add_filter(“the_excerpt”, “trim_excerpt”);

Tips on rebuilding post cache in vbulletin

Some plugins may modify the content of the forum post upon saving or displaying. Updating the post cache under vbulletin admin -> maintenance would not take that into consideration. The best way to update the post cache is to let it rebuilt itself when the page is being requested. To do that, we just need [...]

debugging in smarty

if smarty is not rendering correctly, add the following options
$this->smarty->force_compile = true;
$this->smarty->debugging = true;
$this->smarty->error_reporting = true;
this should provide more information on what’s wrong.

using git ignore

gitignore is helpful when you want to ignore certain files (such as the config files) while working on the files checked out from a git repository. You do not want to commit the config files because other people working on the same repository would also pull your config files which is bad.
Why ignore? because it [...]

parsing html to be xml compliant

htmlentities is not meant for this, use htmlspecialchars instead, ie
htmlspecialchars($var, ENT_NOQUOTES, ‘UTF-8′);
a one liner that can save the day…