PHP Functions
function SafeURL($string){
$string = strtolower($string); // Makes everything lowercase (just looks tidier).
$string = preg_replace('/[^a-z0-9]+/', '-', $string); // Replaces all non-alphanumeric characters with a hyphen.
$string = preg_replace('/[-]{2,}/', '-', $string); // Replaces one or more occurrences of a hyphen, with a single one.
// $string = preg_replace('%', '-percentage', $string);
$string = trim($string, '-'); // This ensures that our string doesn't start or end with a hyphen.
return $string;
}
function create_url_slug($string){
$slug=preg_replace('/[^A-Za-z0-9-]+/', '-', $string);
$string = preg_replace('/[^a-z0-9]+/', '-', $string); // Replaces all non-alphanumeric characters with a hyphen.
return $slug;
}
echo create_url_slug('this is the example demo page');
// This will return 'this-is-the-example-demo-page'
function SafeURL($string){
$string = strtolower($string); // Makes everything lowercase (just looks tidier).
$string = preg_replace('/[^a-z0-9]+/', '-', $string); // Replaces all non-alphanumeric characters with a hyphen.
$string = preg_replace('/[-]{2,}/', '-', $string); // Replaces one or more occurrences of a hyphen, with a single one.
// $string = preg_replace('%', '-percentage', $string);
$string = trim($string, '-'); // This ensures that our string doesn't start or end with a hyphen.
return $string;
}
function create_url_slug($string){
$slug=preg_replace('/[^A-Za-z0-9-]+/', '-', $string);
$string = preg_replace('/[^a-z0-9]+/', '-', $string); // Replaces all non-alphanumeric characters with a hyphen.
return $slug;
}
echo create_url_slug('this is the example demo page');
// This will return 'this-is-the-example-demo-page'
// CURL POST
function post_to_url($url, $data){
$fields = '';
foreach($data as $key => $value){
$fields .= $key . '=' . $value . '&';
}
rtrim($fields, '&');
$post = curl_init();
curl_setopt($post, CURLOPT_URL, $url);
curl_setopt($post, CURLOPT_POST, count($data));
curl_setopt($post, CURLOPT_POSTFIELDS, $fields);
curl_setopt($post, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($post);
curl_close($post);
}
function post_to_url($url, $data){
$fields = '';
foreach($data as $key => $value){
$fields .= $key . '=' . $value . '&';
}
rtrim($fields, '&');
$post = curl_init();
curl_setopt($post, CURLOPT_URL, $url);
curl_setopt($post, CURLOPT_POST, count($data));
curl_setopt($post, CURLOPT_POSTFIELDS, $fields);
curl_setopt($post, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($post);
curl_close($post);
}
0 Comments