javascript - Font Awesome and Unicode Characters Materialize -
i using google's css framework materialize nice.
this framework has own select element dynamically changes ul.
i using fontawesome icons css framework , idea put icon in select follows
<select name="note[type]"> <option value="1"><i class="fa fa-car"></i>car</option> </select>
but not display icon on other hand if write: 
instead of <i>
tag gets displayed correctly (note not actual code of car icon).
so question is: fill icons dynamically database, there way icon class such fa-car
unicode character via php/javascript?
thanks , regards
i have solved in own way here answer might have problem:
first of on stackoverflow found how breakcss array using function:
private function breakcss($css) { $results = array(); preg_match_all('/(.+?)\s?\{\s?(.+?)\s?\}/', $css, $matches); foreach($matches[0] $i=>$original) foreach(explode(';', $matches[2][$i]) $attr) if (strlen(trim($attr)) > 0) // missing semicolon on last element, legal { list($name, $value) = explode(':', $attr); $results[$matches[1][$i]][trim($name)] = trim($value); } return $results; }
i loaded fontawesome code using file_get_contents
, passed breakcss.
all below:
public function geticon($icon) { $icon = $icon.":before"; $fa = file_get_contents(a_css.directory_separator."font-awesome.min.css"); $arr = $this->breakcss($fa); $char = ""; foreach($arr $selector=>$style) { if (strpos($selector, $icon)) { $char = str_replace("\\", "&#x", str_replace("\"", "", $style['content'])).";"; } } return $char; }
usage geticon("fa-car");
hope helps!
Comments
Post a Comment