PHP: Regex for get everything after last forward slash
[code language=”php”] $str ="AAA/CCC"; $output = preg_replace(‘/^.*\/\s*/’, ”, $str); echo $output; [/code] Output: CCC
[code language=”php”] $str ="AAA/CCC"; $output = preg_replace(‘/^.*\/\s*/’, ”, $str); echo $output; [/code] Output: CCC
[code language=”php”] if((!(isset($_SERVER[‘HTTPS’]))) || ($_SERVER[‘HTTPS’] == "") || ($_SERVER[‘HTTPS’] == "off")) header("Location: https://" . $_SERVER[‘HTTP_HOST’] . $_SERVER[‘PHP_SELF’]); [/code]
Sometimes, you might want to get the current page URL that is shown in the browser URL window. For example if you want to let your visitors submit a blog post to Digg you need to get that same exact URL. There are plenty of other reasons as well. Here is how you can do…
[code language=”php”] $path = ‘extracted’; // ‘.’ for current foreach (new DirectoryIterator($path) as $file) { if($file->isDot()) continue; if($file->isDir())) { print $file->getFilename() . ‘<br />’; } } [/code]
[code language=”css”] $position=14; // Define how many character you want to display. $message="You are now joining over 2000 current"; $post = substr($message, 0, $position); echo $post; echo "…"; [/code]