Some helpful PHP functions you might not know they EXIST!!
PHP October 23rd, 2007
http_build_query();
This function can be very helpful when you want to generate URL-encoded query string from an array.
ignore_user_abort();
The ignore_user_abort function is useful when you are executing sensitive code (storing/making changes to db) and you don’t want to stop execution even if the user aborts the connection or browser crashes.
Some cool ways to implement this function is by using it along with ajax. You can allow the server to execute a script in the back-end thus allowing the server to have a faster response time, allowing the user to have a greater site experience. But be sure to validate/check the data before issuing a success response.
ignore_user_abort(true);
header(”Connection:close”);
header(”Content-lenght:”,mb_strlen($response));
echo $response;
flush();
Executed on script end:
function shutdown(){}
register_shutdown_function(’shutdown’);
you can use a flag to verify the script ended successfully!
set_time_limit(numofsec);
It will set a script execution time at the time is included.. can be useful to allow more execution time.
strip all tags from input:
strip_tags($input);
SPELL CHECKING
pspell();
$dict=pspell_new(’en’);
$words=str_word_count($str,2);
foreach($words as $word){
if(!(pspell_check($dict,$word))){
$suggest=pspell_suggest($dict, $word);
echo “{$word}:”,implode($suggest,’,'),”<br/>”;
}
}
SIMILAR TEXT
levenshtein();
returns the number of changes needed:
$diff=levenshtein($name, ‘Julian’);
similar_text();
can give you a percentage of similarity.. slower but useful
Soudex/Metaphone
Metaphone is ’supposed’ to be more accurate since it understands.
Posts
Leave a Comment
You must be logged in to post a comment.