3 Useful PHP Custom Functions That Every Developer Should Know

FirewallFox

FirewallFox

Active Member
Joined
October 26, 2025
Messages
74
Reaction score
74
Points
18
The following three custom functions can be used in PHP applications to help make development easier and faster.


Code:
<?php
// Returns TRUE if the given string is a valid URL
function isValidUrl($url) {
return filter_var($url, FILTER_VALIDATE_URL);
}

// Encrypts a string using a given key
function encryptString($string, $key) {
return base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $string, MCRYPT_MODE_ECB));
}

// Decrypts a string using a given key
function decryptString($string, $key) {
return mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, base64_decode($string), MCRYPT_MODE_ECB);
}
?>

That's it! Now you can use these functions to quickly validate URLs, encrypt strings, and decrypt strings.
1f510.png
 
  • Tags
    custom functions php php for developers programming tips web development
  • Top