In this article, I will provide you php method script to generate SEO-friendly URL for web applications using PHP.
We will discuss how to generate SEO friendly url using PHP, Now days we are using query strings in web url to pass information between your web pages.
In this article, we will learn how to generate SEO-friendly URLs from query string values.
Query string attached parameters onto end of URL after the question mark. We have defined the function to get the Search Engine Friendly Page URL from the given string.
Let’s create a seoUrl()
method that will first remove HTML tags if any are found, Then we’ll remove special characters, trim the white space.
Finally, We will replace whitespace with hyphen and convert a string into lower characters.
/** Description: Prepare SEO Friendly URL result: SEO Frinedly URL out by replacing spaces and special characters with slash(/) */function seoUrl() { $PageTitle="id=1 & name='parvez'"; // Remove HTML Tags if found $string=strip_tags($string); // Replace special characters with white space $string=preg_replace('/[^A-Za-z0-9-]+/', ' ', $string); // Trim White Spaces and both sides $string=trim($string); // Replace whitespaces with Hyphen (-) $string=preg_replace('/[^A-Za-z0-9-]+/','/', $string); // Conver final string to lowercase $slug=strtolower($string); echo $slug; } // result: id/1/name/parvez
This tutorial helps integrate a PHP SDK with Laravel. We'll install aws-php-sdk into laravel application and access all aws services… Read More
in this quick PHP tutorial, We'll discuss php_eol with examples. PHP_EOL is a predefined constant in PHP and represents an… Read More
This Laravel tutorial helps to understand table Relationships using Elequonte ORM. We'll explore laravel table Relationships usage and best practices… Read More
We'll explore different join methods of Laravel eloquent with examples. The join helps to fetch the data from multiple database… Read More
in this Laravel tutorial, We'll explore valet, which is a development environment for macOS minimalists. It's a lightweight Laravel development… Read More
I'll go through how to use soft delete in Laravel 10 in this post. The soft deletes are a method… Read More
View Comments
nice thanks for sharing its useful code....