Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if (isset($_GET['text'], $_GET['keys'])) {
- $textString = $_GET['text'];
- $keysString = $_GET['keys'];
- $keyPattern = "/([A-z]*_?)\d+.*\d([A-z]*_?)/";
- preg_match_all($keyPattern, $keysString, $keyMatches);
- $start = $keyMatches[1][0];
- $end = $keyMatches[2][0];
- $textPattern = "/$start?[a-z]*(\d+\.?\d+)$end/";
- preg_match_all($textPattern, $textString, $textMatches);
- $sum = 0;
- if (empty($start) || empty($end)) {
- echo "<p>A key is missing</p>";
- } else {
- for ($i = 0; $i < count($textMatches[1]); $i++) {
- $sum += $textMatches[1][$i];
- }
- if ($sum == 0) {
- echo "<p>The total value is: <em>nothing</em></p>";
- } else {
- echo "<p>The total value is: <em>$sum</em></p>";
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement