close ad
Databridge V2 with MySQLi support IS Now Available!
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

creating a slug from title field

Thread began 1/02/2016 12:20 pm by Sweens | Last modified 1/04/2016 12:12 pm by Sweens | 294 views | 1 replies

Sweens

creating a slug from title field

Hi

(Happy New Year!)

I've modified the Dreamweaver snippet slightly to produce a php lowercase slug:

<?php
function create_slug($string, $charset = 'utf-8'){
$string = htmlentities($string, ENT_NOQUOTES, $charset, false); // convert accented characters to entities
// strip unwanted parts of entities to leave unaccented character
$string = preg_replace('~&([A-za-z])(?:acute|cedil|caron|circ|grave|orn|ring|slash|th|tilde|uml);~', '\1', $string);
$string = preg_replace('~&([A-za-z]{2})(?:lig);~', '\1', $string);
$string = strtolower($string);
$string = preg_replace('~&[^;]+;~', '', $string); // remove other entities
return preg_replace('~[\s!*\'();:@&=+$,/?%#[\]]+~', '-', $string); // replace spaces and illegal characters with hyphens
}
echo create_slug("Something here! NO CAPITALS")."<br>";// returns 'something-here-no-capitals'
?>

(The 'Something here...' text is the database title field value)

After adding the record, the user is redirected to the page where the slug is generated in a form field - this page updates on load, then on to the 'real' destination, but it would be even better if the slug could be added when the page is created or updated.

How might I achieve this?
Many thanks in anticipation

Chris

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...