Here we are going to see how to make SEO friendly custom blogger or wordpress like URL by using PHP, it is simple process with one small function, but here I'm going to make one small form to get blog title from that title, we will convert that title into blog url. let's see the code.
HTML CODE
<!DOCTYPE html>
<html>
<head>
<title>Custom blog url in php</title>
<style type="text/css">
*{
margin: 0;
}
.blog_form{
margin-top: 4%;
}
.blog_title{
padding: 1%;
width: 500px;
margin-bottom: 1%;
}
.submitbutton{
background-color: #5b695b;
padding: 1%;
color: white;
}
</style>
</head>
<body>
<div align="center" style="margin-top: 3%;">
<h3><b>Blog Title : </b> <?php if(isset($text)){ echo $text; } ?></h3>
<form class="blog_form" id="blog_form" name="blog_form" method="post">
<input type="text" name="blog_title" class="blog_title" required="">
<br>
<input type="submit" name="submit" class="submitbutton" value="submit">
</form>
</div>
</body>
</html>
PHP CODE
<?php
if (isset($_POST['submit'])) {
$blogtitle = $_POST['blog_title'];
// replace non letter or digits by -
$text = preg_replace('~[^\\pL\d]+~u', '-', $blogtitle);
// trim
$text = trim($text, '-');
// transliterate
$text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
// lowercase
$text = strtolower($text);
// remove unwanted characters
$text = preg_replace('~[^-\w]+~', '', $text);
}
?>
The above code will help you to make this easy. i hope this will help you. keep following for more tutorials like this, stay connected with us in all social media.
No comments:
Post a Comment