Welcome aboard! We are happy you are here and wish you good net-raft!
<!DOCTYPE html>
<html lang="en-US">
<head>
</head>
<body>
<?php
function CreateSeoURL($string, $wordLimit = 0){
$separator = '-';
if($wordLimit != 0){
$wordArr = explode(' ', $string);
$string = implode(' ', array_slice($wordArr, 0, $wordLimit));
}
$quoteSeparator = preg_quote($separator, '#');
$trans = array(
'&.+?;' => '',
'[^\w\d _-]' => '',
'\s+' => $separator,
'('.$quoteSeparator.')+'=> $separator
);
$string = strip_tags($string);
foreach ($trans as $key => $val){
$string = preg_replace('#'.$key.'#i'.(UTF8_ENABLED ? 'u' : ''), $val, $string);
}
$string = strtolower($string);
return "https://$_SERVER[SERVER_NAME]/" . trim(trim($string, $separator));
}
$Title = 'How to get input field value using PHP';
echo CreateSeoURL($Title, 6) . "</p>"; // with word limit
echo CreateSeoURL($Title);
?>
</body>
</html>
<!DOCTYPE html>
<html lang="en-US">
<head>
</head>
<body>
<?php
function friendlyUrl($title){
$url = $title;
$url = preg_replace('~[^\\pL0-9_]+~u', '-', $url);
$url = trim($url, "-");
$url = iconv("utf-8", "us-ascii//TRANSLIT", $url);
$url = strToLower($url);
$url = preg_replace('~[^-a-z0-9_]+~', '', $url);
return "https://$_SERVER[SERVER_NAME]/" . $url;
}
?>
<?php
echo friendlyUrl("RewriteRule ^article in php");
?>
</body>
</html>
The most helpful PHP solutions
detect browser phpPHP Click to see more ... 4.6K 408