Utilizing URLs on your site that are program friendly is straight forward and straight forward to try to to because of PHP and Apache. we’ll be utilizing permalinks that get obviate all the nasty $_GET data that trails the top of most PHP scripts. An example of a SEO unfriendly URL we’ll clean is:
http://www.domaincom/post.php?id=123&title=seo-php-url
Using a combination of Apache’s ForceType directive, the PHP explode() function and PHP’s PATH_INFO variable we will easily turn the sample URL into:
http://www.domain.com/post/123/seo-php-url
This not only helps our website’s SEO (search engine optimization), but also accomplishes a security concept is understood as “security by obscurity”. By obscuring the very fact that our internet site is employing a PHP script, we may detract potential hackers from trying to find exploits within our scripts.
Follow below code for
Step1: First remove all special character from url
use this function to clean your url
$title=trim(htmlspecialchars($_POST['title'], ENT_QUOTES));
function clean($title) {
$string = str_replace(' ', '-', $title); // Replaces all spaces with hyphens.
$string = preg_replace('/[^A-Za-z0-9\-]/', '', $string); // Removes special chars.
return preg_replace('/-+/', '-', $string); // Replaces multiple hyphens with single one.
}
$slug=strtolower(clean($title));
Explanation Of above code
in $title you store form title value and remove space from both end and Convert the predefined characters “<” (less than) and “>” (greater than) to HTML entities
and most important to use clean function .
In this function you just need to pass title value and use this function value in $slug ou your desire url valriable
just it
Learn how to efficiently set up auto-increment columns in PostgreSQL with this step-by-step guide. From…
Just use below code and modified according to your need. Note: this is very useful…