Horje

Tips (Total 1)


# Tips-1) 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