Horje
How to create title to url/slug in PHP

This is php function which will make a title to URL


First create a PHP Function

Following string Function will replace from title to slug
index.php
Example: PHP
<?php
function permalink($var)
{
$var=preg_replace('#([\W_]+)#',' ',$var);
$var=str_replace('?','',$var);
$var=str_replace(' ','-',$var);
$var=strtolower($var);
return $var;
}
?>

Now, Use a "permalink" tag to title string

index.php
Example: PHP
<?php
// Your title
$slug = 'How to create a video';
// Resule
echo permalink($slug);
?>

Output should be:

Now, Use a

Or

index.php
Example: PHP
<?php
// Resule
echo permalink('How to create a video');
?>

Output should be:

Or

Set your domain like this

index.php
Example: PHP
<?php
// Your title
$slug = permalink('How to create a video');
// Resule
echo 'yourdomain.com/'.$slug.'';
?>

Output should be:

Set your domain like this

Full Completed Code

Here is given full example
index.php
Example: PHP
<?php
function permalink($var)
{
$var=preg_replace('#([\W_]+)#',' ',$var);
$var=str_replace('?','',$var);
$var=str_replace(' ','-',$var);
$var=strtolower($var);
return $var;
}
?>
<?php
// Your title
$slug = permalink('How to create a video');
// Resule
echo 'yourdomain.com/'.$slug.'';
?>

Output should be:

Full Completed Code






Related Articles
How to create title to url/slug in PHP PHP Function Tutorial

Single Articles
First create a PHP FunctionPHP Function Tutorial
Now, Use a "permalink" tag to title stringPHP Function Tutorial
OrPHP Function Tutorial
Set your domain like thisPHP Function Tutorial
Full Completed CodePHP Function Tutorial

Read Full:
PHP Function Tutorial
Category:
Web Tutorial
Sub Category:
PHP Function Tutorial
Uploaded:
1 year ago
Uploaded by:
Admin
Views:
76
Tested on:
PHP 5.6, 7, 8



Share on: