Feb 12, 2009

PHP: array delete

//deletes a number on index $idx in array and returns the new array
function array_delete($idx,$array) {
 return (is_array($array)) ? array_values($array) : null;

Feb 9, 2009

PHP: substring between two substrings in a string

Useful if you want to, for example get the text between HTML tags
 function between($s,$l,$r) {
  $il = strpos($s,$l,0)+strlen($l);
  $ir = strpos($s,$r,$il);
  return substr($s,$il,($ir-$il));

$html = file_get_contents('http://www.example.com');
$title = between($html,'<title>','</title>');

For more complex searches, you would need to use regular expressions.