Skip to content

Instantly share code, notes, and snippets.

@Alexander-Pop
Alexander-Pop / check-if-valid-url.php
Last active February 1, 2019 16:55 — forked from thagxt/check-if-valid-url.php
check if url is valid #php #url
<?php
/* @ http://stackoverflow.com/a/12628971 */
function isValidUrl($url){
// first do some quick sanity checks:
if(!$url || !is_string($url)){
return false;
}
// quick check url is roughly a valid http request: ( http://blah/... )
if( ! preg_match('/^http(s)?:\/\/[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(\/.*)?$/i', $url) ){
return false;
@Alexander-Pop
Alexander-Pop / url-check.php
Last active February 1, 2019 16:56 — forked from thagxt/url-check.php
php check headers status going thru all page statuses #php #url
<?php
/* @ http://stackoverflow.com/a/12628971 */
function getHttpResponseCode_using_getheaders($url, $followredirects = true){
// returns string responsecode, or false if no responsecode found in headers (or url does not exist)
// NOTE: could potentially take up to 0-30 seconds , blocking further code execution (more or less depending on connection, target site, and local timeout settings))
// if $followredirects == false: return the FIRST known httpcode (ignore redirects)
// if $followredirects == true : return the LAST known httpcode (when redirected)
if(! $url || ! is_string($url)){
return false;
@Alexander-Pop
Alexander-Pop / rename-file.php
Last active February 1, 2019 16:56 — forked from thagxt/rename-file.php
Quickly rename a file name with PHP. w/ error handling #php #file
<?php
$oldname = "index.html";
$newname = "index.php";
// checking if file exist or not.
if ( file_exists($oldname) && ( (!file_exists($newname))|| is_writable($newname) ) ) {
$renameResult = rename($oldname, $newname);
die($oldname . " renamed to " . $newname);
} else {
die('nothing to rename.');
@Alexander-Pop
Alexander-Pop / Install Composer to use MAMP's PHP.md
Created July 25, 2023 13:33 — forked from kkirsche/Install Composer to use MAMP's PHP.md
How to install Composer globally using MAMP's PHP

##Create an alias to MAMP's PHP installation

To do this, we can simply create an alias for our bash profile. We'll be doing this is nano, though you can do it in vim or a number of other editors as well.

Within the terminal, run:

nano ~/.bash_profile

This will open nano with the contents, at the top in a blank line add the following line: