Regular Expressions 101

Community Patterns

Community Library Entry

1

Regular Expression
PCRE (PHP <7.3)

/
>&(.*)<\/i>[\r\n]\s{6}(.*)
/
g

Description

Page with icons

PHP example: Generate xml for android resources

header('Content-Description: File Transfer');
header("Content-Type: text/xml");
header('Content-Disposition: attachment; filename="icons.xml"');

$Url = "http://fontawesome.io/cheatsheet/";
$Page = file_get_contents($Url);

$Pattern = '/>&(.*)<\/i>[\r\n]\s{6}(.*)/';
preg_match_all($Pattern, $Page, $IconArray, PREG_PATTERN_ORDER);

$Count = count($IconArray[0]);

echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>"."\r\n";
echo "<resources>"."\r\n";
for ($i = 0; $i < $Count; $i++) {
  $IconHex = $IconArray[1][$i];
  $IconTitle = $IconArray[2][$i];
  $IconTitle = str_replace("-", "_", $IconTitle);
  echo "    <string name=\"$IconTitle\">&$IconHex;</string>"."\r\n";
}
echo "</resources>";
Submitted by IgorSkv - 8 years ago