Return content between delimiters
function extract_unit($string, $start, $end)
{
$pos = stripos($string, $start);
$str = substr($string, $pos);
$str_two = substr($str, strlen($start));
$second_pos = stripos($str_two, $end);
$str_three = substr($str_two, 0, $second_pos);
$unit = trim($str_three); // remove whitespaces
return $unit;
}
CODE
PHP
Replace content in a string within delimiters
function replace_content_inside_delimiters($start, $end, $new, $source) {
return preg_replace('#('.preg_quote($start).')(.*)('.preg_quote($end).')#si', $new, $source);
}
CODE
PHP
Internet Explorer reminder
When working with Javascript files in Internet Explorer, if IE finds a syntax error anywhere in an external .js file, instead of giving you an error message telling you there's an error, it will simply disregard ALL code in the ENTIRE .js file.
The only error message it gives you is a notice that, whenever you try to use a function located in the offending .js file, the function does not exist.
Thank you, Microsoft, for this wonderful feature -_-
Anyway, note to self: Putting a comma after the end of a comma-separated list (in my case, leaving a comma at the end of the last item in a list of options for a MooTools class), will be considered a syntax error in IE. Both Firefox and Safari have no problem with it. (not to mention PHP).
REMINDERS
Find a specific file in a specified directory
// Locates the first file with a name matching the passed string
// and returns its path relative to the path passed
// You can also pass it an array, and it will search the array for
// a value matching the $file.
// If you pass an extension, it will only look for files with that ext
function findFile($file, $dir, $ext=''){
if($ext)$file.=$ext;
if(!is_array($dir)){
if($dir[strlen($dir)-1]!='/')$dir.='/';
$path = $dir;
$dir = dirList($dir);
}
foreach($dir as $k=>$v){
if(is_array($v) && !$location){
$x = findFile($file, $v);
if($x)$location .= $k.'/'.$x;
}
else if($v == $file && !$location)$location .= $v;
}
if($location)return $location;
}
CODE
PHP