url-titel-generator-controle
Gesponsorde koppelingen
PHP script bestanden
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<?php
function URLstring($input){
// delete some chars that not may be replaced with a space char
$temp = str_replace(array("'",'"'),'',$input);
// replace special chars by readable variant
$temp = str_replace(array('&','@','$'),array(' en ',' at ','dollar'),$temp);
// replace strange chars to their equivalent
$temp = preg_replace('#&(.)[a-z]+;#','$1',htmlentities($temp));
// replace all others by an underscore
$temp = preg_replace('#[^a-zA-Z0-9\-]+#','_',$temp);
// done, clean up and return the result
return trim($temp,'-_');
}
function is_validURLstring($string){
return ($string === urlencode($string));
}
?>
function URLstring($input){
// delete some chars that not may be replaced with a space char
$temp = str_replace(array("'",'"'),'',$input);
// replace special chars by readable variant
$temp = str_replace(array('&','@','$'),array(' en ',' at ','dollar'),$temp);
// replace strange chars to their equivalent
$temp = preg_replace('#&(.)[a-z]+;#','$1',htmlentities($temp));
// replace all others by an underscore
$temp = preg_replace('#[^a-zA-Z0-9\-]+#','_',$temp);
// done, clean up and return the result
return trim($temp,'-_');
}
function is_validURLstring($string){
return ($string === urlencode($string));
}
?>
Code (php)
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
<?php
$string = 'Hipska\'s eerste bericht:"Één grote test met tekens enzo."';
$url = URLstring($string);
var_dump($string,$url,is_validURLstring($url));
?>
string(57) "Hipska's eerste bericht:"n grote test met tekens enzo.""
string(53) "Hipskas_eerste_bericht_Een_grote_test_met_tekens_enzo"
bool(true)
$string = 'Hipska\'s eerste bericht:"Één grote test met tekens enzo."';
$url = URLstring($string);
var_dump($string,$url,is_validURLstring($url));
?>
string(57) "Hipska's eerste bericht:"n grote test met tekens enzo.""
string(53) "Hipskas_eerste_bericht_Een_grote_test_met_tekens_enzo"
bool(true)