Remove substring from string in PHP
/** * Remove substring from string * * Here is an inline example: * <code> * <?php * echo rmv(‘mxaxuxix’, ‘x’); // return ‘maui’; * * ?> * </code> * @param string $subject * @param…
/** * Remove substring from string * * Here is an inline example: * <code> * <?php * echo rmv(‘mxaxuxix’, ‘x’); // return ‘maui’; * * ?> * </code> * @param string $subject * @param…
function att($arr, $class = null) { $return = “<table” . (!is_null($class) ? ‘ class = “‘ . $class . ‘”‘ : null) . “>”; foreach ($arr as $key => $value) { $return .= “<tr>”; foreach…
<?php // Get current protocol. $protocol = stripos($_SERVER[‘SERVER_PROTOCOL’],’https’) === 0 ? ‘https://’ : ‘http://’; // Get current domain. $domain = $_SERVER[‘HTTP_HOST’]; // Get current path to the current file. $path = $_SERVER[‘SCRIPT_NAME’]; // Get current…
Here is a simple but useful function to remove substrings within a string in PHP. The second parameter can be a string or an array of strings, in this case all strings in the array…
$mbox = imap_open(“{mail.example.com:143/novalidate-cert}”, “foo@example.com”, “password”) or die(“can’t connect: ” . imap_last_error()); $folders = imap_list($mbox, “{mail.example.com:143/novalidate-cert}”, “*”); if ($folders === false) { echo “Failed to list folders in mailbox”; } else { print_r($folders); } imap_close($mbox);
$alltables = mysqli_query($conn, "SHOW TABLES"); while ($table = mysqli_fetch_assoc($alltables)){ foreach ($table as $db => $tablename){ echo "OPTIMIZE TABLE `".$tablename."`"; mysqli_query($conn, "OPTIMIZE TABLE `".$tablename."`") or die(mysqli_error()); echo "<br>"; } }
<?php function str_lreplace($search, $replace, $subject) { $pos = strrpos($subject, $search); if($pos !== false) { $subject = substr_replace($subject, $replace, $pos, strlen($search)); } return $subject; } $search = ".Maui"; $replace = "is awesome"; $subject = ".Maui .Maui";…
This script written in PHP will delete emails older than 120 days from an imap email account. <?php $days = 120; $time = strtotime(date(“Y-m-d”) . ” – ” . $days . ” days”); $date =…
We have just released a new version of the API to minimize CSS. Based on your feedback we have added four new parameters: removeurlquotes: Removes quotes from urls. Default is true.removecomments: Removes all comments. Default…
<?php $date1 = strtotime("2019-02-01"); $date2 = strtotime("2019-07-26"); $diff_unix = $date2 – $date1; $diff_days = floor($diff_unix/3600/24); echo $diff_days; // Result: 175