Created
June 7, 2018 10:27
-
-
Save hsali/028ce36995446e970ab32eeca30280b4 to your computer and use it in GitHub Desktop.
convert HTML select element key values to constant property of PHP Class with comments
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
art = document.querySelectorAll("#your-select-element-id-here option"); | |
function tag_g(tag_name, tag_value){ | |
clean_name = tag_name.replace('-'," "); | |
clean_name = clean_name.replace('&',"AND"); | |
clean_name = clean_name.replace(/\s\s+/g, ' '); | |
clean_name = clean_name.replace(/[^a-zA-Z ]/g, " "); | |
tag_slug = clean_name.toUpperCase().split(" ").join("_"); | |
tag_str ="\ | |
/** \n \ | |
* " + tag_name + "\n \ | |
*/\n \ | |
const " + tag_slug+ " = "+ tag_value+";"; | |
tag_str += "\n"; | |
return tag_str; | |
} | |
tags_str = ""; | |
for (i=1; i< art.length; i++){ | |
tags_str += tag_g(art[i].innerText, art[i].value); | |
} | |
console.log(tags_str); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment