LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!
<?php
function create_seo_slug($string, $ext='.html'){
$replace = '-';
$string = strtolower($string);
//replace / and . with white space
$string = preg_replace("/[\/\.]/", " ", $string);
$string = preg_replace("/[^a-z0-9_\s-]/", "", $string);
//remove multiple dashes or whitespaces
$string = preg_replace("/[\s-]+/", " ", $string);
//convert whitespaces and underscore to $replace
$string = preg_replace("/[\s_]/", $replace, $string);
//limit the slug size
$string = substr($string, 0, 100);
//slug is generated
// if extension is specified, return string plus extension else return string.
return ($ext) ? $string.$ext : $string;
}
//INPUT
$string = "what is your name ?";
$slug = create_seo_slug($string);
//OUTPUT::
//what-is-your-name.html
?>
Does anyone have any guidance on how to easily make a livecode equivalent of the PHP preg_replace ? All I need to do duplicate the above code so that it runs in a livecode app and generates the same/correct seo slug url's.
function create_seo_slug T, theExtension
local theReplace = "-" // $replace = '-';
put toLower( T) into T
//replace / and . with white space
put replaceText( T, "[/.]", space) into T
// $string = preg_replace("/[^a-z0-9_\s-]/", "", $string);
put replaceText( T, "[^a-z0-9_\s-]", empty) into T
//remove multiple dashes or whitespaces [1]
put replaceText( T, "[\s-]+", space) into T
//convert whitespaces and underscore to $replace
put replaceText( T, "[\s_]", theReplace) into T
// limit the slug size
put char 1 to 100 of T into T
// if extension is specified, return string plus extension else return string.
if theExtension is empty then return T
return T & theExtension
end create_seo_slug
Greetings from France
Thierry
! SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
That works wonderfully. I didn't know replaceText could handle regex. Thanks so much - Wish I could hand you one in person, but this will have to do http://beeroverip.org/london-porter/