Math Functions:
String Functions:
Text Functions:
Code:
function distance($x1, $y1, $x2, $y2) { $x = pow($y2 - $y1, 2); $y = pow($x2 - $x1, 2); $distance = sqrt($x + $y); return $distance; } function midpoint($x1, $y1, $x2, $y2) { $x = ($x1 + $x2)/2; $y = ($y1 + $y2)/2; $midpoint = '('.$x.','.$y.')'; return $midpoint; } function calculate($equation) { $equation = ereg_replace('([A-Z]|[a-z])', '', $equation); $answer = eval('return '.$equation.';'); return $answer; }
Code:
function array_stristr($text, $search) { $num_matches = 0; for($i = 0; $i < count($search); $i++) { if(stristr($text, $search[$i])) { $num_matches++; } } return $num_matches; } function get_words($text, $offset, $length=null) { $text = explode(' ', $text); if($length) $text = array_slice($text, $offset, $length - $offset + 1); else $text = array_slice($text, $offset); $text = implode(' ', $text); return $text; }
Code:
function alternating_caps($text) { $text = strtolower($text); $x = 1; for($i = 0; $i < strlen($text); $i++) { if($x == 1) { $text{$i} = strtoupper($text{$i}); $x = 2; } elseif($x == 2) { $x = 1; } } return $text; } function random_caps($text) { $text = strtolower($text); for($i = 0; $i < strlen($text); $i++) { $x = round(rand(0, 1)); if($x == 1) { $text{$i} = strtoupper($text{$i}); } elseif($x == 2) { } } return $text; }