Skip to content

Commit fac3ce1

Browse files
committed
Use foreach rather than /etc/profile.d/*.sh
1 parent 2515338 commit fac3ce1

1 file changed

Lines changed: 8 additions & 12 deletions

File tree

php/getWolframData.php

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,31 +42,27 @@ function parsePlainText($key, $pod) {
4242
switch($key) {
4343
case 'nearbyCities2':
4444
$replaceWith = '</li><li>';
45-
$i = 0;
4645

4746
$plaintext = preg_replace('/\(straight-line distance to city centers\)/', '', $plaintext);
4847
preg_match_all('/people/', $plaintext, $matches, PREG_OFFSET_CAPTURE);
4948

50-
foreach($matches[0] as $match) {
51-
if($i == count($matches[0]) - 1) { continue; }
52-
$plaintext = substr_replace($plaintext, $replaceWith, strlen($match[0]) + $match[1] + 1 + $i * strlen($replaceWith), 0);
53-
$i++;
49+
foreach($matches[0] as $key => $match) {
50+
if($key == count($matches[0]) - 1) { continue; }
51+
$plaintext = substr_replace($plaintext, $replaceWith, strlen($match[0]) + $match[1] + 1 + $key * strlen($replaceWith), 0);
5452
}
5553

5654
return '<ul><li>' . $plaintext . '</li></ul>';
5755
break;
5856

5957
case 'nearbyFeatures':
6058
$replaceWith = '</li><li>';
61-
$i = 0;
6259

6360
$plaintext = preg_replace('/\(straight-line distance to feature center\)/', '', $plaintext);
6461
preg_match_all('/miles [a-zA-Z0-9\-]+/', $plaintext, $matches, PREG_OFFSET_CAPTURE);
6562

66-
foreach($matches[0] as $match) {
67-
if($i == count($matches[0]) - 1) { continue; }
68-
$plaintext = substr_replace($plaintext, $replaceWith, strlen($match[0]) + $match[1] + 1 + $i * strlen($replaceWith), 0);
69-
$i++;
63+
foreach($matches[0] as $key => $match) {
64+
if($key == count($matches[0]) - 1) { continue; }
65+
$plaintext = substr_replace($plaintext, $replaceWith, strlen($match[0]) + $match[1] + 1 + $key * strlen($replaceWith), 0);
7066
}
7167

7268
return '<ul><li>' . $plaintext . '</li></ul>';
@@ -81,7 +77,7 @@ function parsePlainText($key, $pod) {
8177
}
8278
}
8379

84-
foreach($dataCategories as $key=>$categoryPods) {
80+
foreach($dataCategories as $key => $categoryPods) {
8581
switch($key) {
8682
case 'categoryNearby':
8783
$class = 'env-data-pod--nearby';
@@ -104,7 +100,7 @@ function parsePlainText($key, $pod) {
104100

105101
echo '<h1><i class=" '. $icon .' "></i>' . $title . '</h1>';
106102

107-
foreach($categoryPods as $key=>$pod) {
103+
foreach($categoryPods as $key => $pod) {
108104
echo '<h2>' . $pod[0]->attributes()->title . '</h2><p>' . parsePlainText($key, $pod) . '</p>';
109105
}
110106

0 commit comments

Comments
 (0)