PHP create friendly url php - Net-Raft.com

Welcome aboard! We are happy you are here and wish you good net-raft!




Just a Web Code Solution

create friendly url in php


 581

PHP


3

<!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>


By     Created   
The power of the user (%)
4%

PHP


2

<!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>


By     Created   
The power of the user (%)
5%



The most helpful PHP solutions

detect browser phpdetect browser phpPHP

Click to see more ...

  3.7K     388

create QR code phpcreate QR code phpPHP

Click to see more ...

  2.3K     274

delete array item phpdelete array item phpPHP

Click to see more ...

  1.9K     231

create relative date phpcreate relative date phpPHP

Click to see more ...

  1.5K     216

detect ie phpdetect ie phpPHP

Click to see more ...

  1.2K     209

get current url phpget current url phpPHP

Click to see more ...

  823     189

Get real client country using php ?Get real client country using php ?PHP

Click to see more ...

  655     169

drag and drop upload file using phpdrag and drop upload file using phpPHP

Click to see more ...

  1.6K     141

get meta tag phpget meta tag phpPHP

Click to see more ...

  566     129

detect speed internet phpdetect speed internet phpPHP

Click to see more ...

  546     106