3 Useful PHP Custom Functions That Every Developer Should Know

  • Thread starter FirewallFox
  • Start date
  • Tagged users None
FirewallFox

FirewallFox

Golden Member
Joined
October 26, 2025
Messages
408
Reaction score
1,017
Points
93
  • Thread Author
  • #1
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