1. Home
  2. Articles
  3. Web Development
  4. PHP
  5. Article Title Conversion to Friendly URL Using PHP String Replace and RegEx
Read about php friendly urls

Article Title Conversion to Friendly URL Using PHP String Replace and RegEx

Published:

Share

Description

There are a couple of items that I will need to address with the dynamic article system. One of those items is providing a easy way to parse out web page names from a title. This should be pretty easy with some regex and string replace php functions.

Article

The purpose of this note is to test the automation process for correctly converting an article title in to a friendly URL. The process uses the PHP str_replace function first to convert spaces to hyphens. Then a the PHP RegEx (preg_replace) furhter filters the article title to alphanumeric and spaces.

Might as well test out the TinyMCE code insert as well.

$myArticleURL = preg_replace("/[^a-zA-Z0-9-]+/", "", str_replace(' ', '-', $_POST['txtArticleTitle']));

If all goes well, the defaulting for article URLs will be complete. I will add some polish by allowing the ability to override the defaulted value with a custom value entered by the user. Maybe later I will look into a dynamic JavaScript or jQuery solution that could replace the server side PHP function with a client side solution.

:D

Author

Profile Picture of Bryan Myers - The Web Guy

Bryan Myers - "The Web Guy"

Advanced Digital Channel Engineer

Tags

  1. Articles discussing web related topics and technologies.Articles
  2. Articles on the Web Development topics.Web Development
  3. Articles covering PHP web development.PHP

Related Articles

Go Back