3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Weather Scraper // Fetch the page for the city $contents = file_get_contents('http://www.weather-forecast.com/locations/Bend/forecasts/latest'); // Extract the 3 day Weather // The following pattern will yeild forecast in $matches[1] as of September 10, 2015 in the U.S.A. // However the multiple <span> blocks may possibly change causing this logic to fail in the future. $pattern = '/3 Day Weather Forecast Summary:<\/b><span class="read-more-small"><span class="read-more-content"> <span class="phrase">(.*?)</s'; preg_match( $pattern, $contents, $matches); $forecast1 = $matches[1]; // Instead, let's take a hopefully more robust approach and extract the forecast from $matches[0] using a less <span> intensive pattern // Note 1: We separately keep track of the search prefix, so we can remove this from the beginning of $matches[0]. // Note 2: We end the search on pattern not with '<', but with '<\/span' because we need to make sure we search to the first closing </span> $patternPrefix = '3 Day Weather Forecast Summary:'; $pattern = '/' . $patternPrefix . '(.*?)<\/span/s'; preg_match( $pattern, $contents, $matches); // $matches[0] starts with the $patternPrefix, so remove that from the beginning. $forecast2 = trim( substr($matches[0], strlen($patternPrefix)) ); echo $forecast1; echo $forecast2;
Output for git.master, git.master_jit, rfc.property-hooks
Warning: file_get_contents(): php_network_getaddresses: getaddrinfo for www.weather-forecast.com failed: System error in /in/6BJho on line 5 Warning: file_get_contents(http://www.weather-forecast.com/locations/Bend/forecasts/latest): Failed to open stream: php_network_getaddresses: getaddrinfo for www.weather-forecast.com failed: System error in /in/6BJho on line 5 Warning: Undefined array key 1 in /in/6BJho on line 13 Warning: Undefined array key 0 in /in/6BJho on line 22 Deprecated: substr(): Passing null to parameter #1 ($string) of type string is deprecated in /in/6BJho on line 22

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
67.17 ms | 402 KiB | 8 Q