How to create SEO Optimized URLs from String in PHP
A uniform resource locator abbreviated URLs or web address used to locate exact information page on the web like https://www.phpgang.com/how-to-create its a URL and how-to-create is created from a string and in this tutorial I will give you a method to know about that function of PHP. This is a very basic solution for beginner PHP Developers and programmers.
Here is the code snippet to create URLs from a String.
function.php
<?php function to_prety_url($str){ if($str !== mb_convert_encoding( mb_convert_encoding($str, 'UTF-32', 'UTF-8'), 'UTF-8', 'UTF-32') ) $str = mb_convert_encoding($str, 'UTF-8', mb_detect_encoding($str)); $str = htmlentities($str, ENT_NOQUOTES, 'UTF-8'); $str = preg_replace('`&([a-z]{1,2})(acute|uml|circ|grave|ring|cedil|slash|tilde|caron|lig);`i', '\1', $str); $str = html_entity_decode($str, ENT_NOQUOTES, 'UTF-8'); $str = preg_replace(array('`[^a-z0-9]`i','`[-]+`'), '-', $str); $str = strtolower( trim($str, '-') ); return $str; } ?>
To use this function you have to create this page index.php which contain function call line with parameters.
<?php include('function.php'); $str = "How to Create HTML5 Form"; // this string will be submitted in parameter. echo to_prety_url($str); // show optimized url string. ?>
This function first of all convert string to utf-8 after that use perg_replace and change white spaces to “-” and remove special characters.
These URLs also make good impact on your SEO and recommended by Google.
Tutorial Categories:
ok, but how will it reflect the string to address bar
@disqus_xCJR1jcNNv:disqus Changes added in article how to use it..
ok when i get the string, i can save in db or use as permalink
but how will it show in address bar in top. i am working on core php no frameworks.
what changes to be made in htaccess
looks good – but how to use it ? By include ?
Thanx
Changes added in article how to use it..
Thank you. Nice info
hello Sir give me some ideas about SEO Please
help Me Sir
i need some help in page url can anybody help me. phpGang team i need some help please
What help you need?
Asalamu Alaikaum,
Dear HuzorBux Sir
i m new in Web Development. i Found your site very late it is very nice and good for learning. The Help i need is that
Can PhpGang Team Help me in Page URL a si asked yesterday
Let sya i have a page url is
sitenamecom/recird .php?id=12&city=37
i want like this sitenamecom/record .php
hope u will understoood
Wsalam
You can do it with .htaccess.
As Salaam O Aleykum Huzoor Sir. May you please publish an article on building blog with all the facilities. like recent post, categories & archives.
hello sir i want userfriendy url without usig httaccess file and webconfig in php