PHP Snippets
find_version
Information
(PHP Version >= 4.3.0)Functions used in this snippet: str_replace, explode, preg_match, strstr, substr, strpos, preg_replace, file_get_contents.
Description
str find_version(str functions)
Finds the newest PHP version needed out of a list of functions. A string is returned with the newest PHP version needed.
Snippet
<?php
function find_version($functions) {
$str = str_replace(array("\r","\n",' ','(',')'),'',$functions);
$fun = explode(',',$str);
$versions = array();
foreach($fun as $key=>$value){
$str = file_get_contents('http://www.php.net/' . str_replace('_','-',$value));
preg_match('/\>\s*\((.+?)\)\<\/P/ims', $str,$matches);
$matches[0] = str_replace(array('3 >= ','4 >= ','5 >= '),'',$matches[0]);
$x = preg_replace('/[^,0-9.]/','',$matches[0]);
$x = strstr($x,',') ? substr($x,0,strpos($x,',')) : $x;
$versions[] = $x;
}
natsort($versions);
$x = end($versions);
return $x;
}
?>
Example
find_version Can be used in the following way:
<?php
echo find_version('file_get_contents,substr,in_array');
// above outputs 4.3.0
echo find_version('str_replace(),str_ireplace()');
// above outputs 5
?>
Updated on Jun 25th at 5 am.
0 Responses to find_version