function to create a uid from html
this function converts a html string into a uid or unique id type string, its not actually unique, but its a string that can be used to make the title of something that contains html into a usable string.
like if you wanted to use it in a url for seo purposes or something like that
so this will take a html sting and convert it into lowercase, strip out the html tags and add dashes instead of spaces, it also remove additional characters that are not A-Za-z0-9
Update: Created a tool from this function where you can add a string and it will create a UID from a string using the same function here.
PHP
$template_result = "";
// function
// another function to create a uid from html
function create_uid_from_html($html) {
$html = strip_tags($html);
$html = str_replace(" ", "-", $html);
$html = str_replace("--", "-", $html);
$html = preg_replace("/[^A-Za-z0-9\-]/", '', $html);
$html = strtolower($html);
$html = substr($html, 0, 99);
$html = trim($html);
return $html;
}
$my_title = "This is the <a href='#!'>title that</a> i am <b>using</b> to create a Unique ID for the current test.";
$my_result = create_uid_from_html($my_title);
$template_result .= "<p>The title <code>$my_title</code> has been converted into <code>$my_result</code></p>";
echo $my_result;
The title
This is the title that i am using to create a Unique ID for the current test.
has been converted into
this-is-the-title-that-i-am-using-to-create-a-unique-id-for-the-current-test