Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

135
Views
How to export class's of css and put into array with php?

hello guyes I have CSS code and I'm trying to find a way to get only the CSS Class's name Only and clear coma and open&close tag and value and put it into an array in PHP

Example:

.dungarees {
  content: "\ef04";
}
.jacket {
  content: "\ef05";
}
.jumpsuit {
  content: "\ef06";
}
.shirt {
  content: "\ef07";
}

and I want to do a a function with PHP to convert it into an array like this

$my_array('dungarees','jacket','jumpsuit','shirt');

is there any function with php or even jquery to deal with this? thanks

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You can create such an array with a simple Regex.

$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);

And will result in

Array
(
    [0] => dungarees
    [1] => jacket
    [2] => jumpsuit
    [3] => shirt
)
about 4 years ago · Juan Pablo Isaza Report

0

Scan the string line by line, expecting it to begin with . and end with {

<?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));
    }
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!