I have an html file and I want to get all the classes from this file in an array using PHP. For example this is my html file:
<div class="main menu">element</div>
<div class="content"></div>
I want to get an array with three elements (in this particular example): "main", "menu", "content".
In bash it is possible to use grep to accomplish this:
classes=($(grep -oP '(?<=class=").*?(?=")' "./index.html"))
How can I do the same in PHP?
I have this basic code at this moment:
//read the entire string
$str = implode("", file('./index.html'));
$fp = fopen('./index.html', 'w');
//Here I guess should be the function to get all of the strings
//now, save the file
fwrite($fp, $str, strlen($str));
Edit: How can my question be the duplicate of the one provided, if I am asking on how find the string using PHP? It is not bash and I have already provided the grep alternative.