hola chicos, tengo un código CSS y estoy tratando de encontrar una manera de obtener solo el nombre de la clase CSS Solo y borrar el coma y abrir y cerrar la etiqueta y el valor y ponerlo en una matriz en PHP
Ejemplo:
.dungarees { content: "\ef04"; } .jacket { content: "\ef05"; } .jumpsuit { content: "\ef06"; } .shirt { content: "\ef07"; }y quiero hacer una función con PHP para convertirla en una matriz como esta
$my_array('dungarees','jacket','jumpsuit','shirt');¿Hay alguna función con php o incluso con jquery para lidiar con esto? Gracias
Puede crear una matriz de este tipo con un Regex simple.
$cssText = <<<'_CSS' .dungarees { content: "\ef04"; } .jacket { content: "\ef05"; } .jumpsuit { content: "\ef06"; } .shirt { content: "\ef07"; } _CSS; $matches = []; preg_match_all('/\.([\w\-]+)/', $cssText, $matches); $myArray = $matches[1]; print_r($myArray);y resultará en
Array ( [0] => dungarees [1] => jacket [2] => jumpsuit [3] => shirt )Escanee la cadena línea por línea, esperando que comience con . y terminar con {
<?php $result = []; $content_of_css = ' .dungarees { content: "\ef04"; } .jacket { content: "\ef05"; } .jumpsuit { content: "\ef06"; } .shirt { content: "\ef07"; } '; // or $content_of_css = file_get_contents("path_to_css"); $arr = explode("\n", $content_of_css); foreach ($arr as $line) { $line = trim($line); if (strrpos($line, ".") === 0) { $result[] = trim(substr($line, 1, strlen($line) - 2)); } }