<?php
$str = '<a href="/good/&id=122321312312&ld=eyJwcm9tb3Rpb25fcHJpY2UiOiI5OC4wMCIsInZvbHVtZSI6Miwic2NvcmUiOjEyLCJzZWxsZXJJZCI6IjE3OTY4NTg3OTAifQ==">Товар 1</a>';
if(preg_match('#&id=(\d+)#si', $str, $matches))
{
print_r($matches);
}
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(array("data"=>$data_string)));
<?php
define('C_TIME_ONE_DAY', 86400);
/**
* @param int $from Дата заказа
* @param int $daysCount Базовое число дней доставки
* @param int $nextDayHour Заказы, сделанные после этого часа доставляются со следующего дня
* @param array $freezeDays Дни недели, в которые заказы не движутся
* @param array $deliveryDays Дни доставки
* @return int
*/
function delivery($from, $daysCount, $nextDayHour, $freezeDays, $deliveryDays)
{
if(!in_array(date('w', $from), $freezeDays)) {
if(date('H', $from) > $nextDayHour - 1) {
$from = strtotime('tomorrow', $from);
} else {
$from = strtotime('midnight', $from);
}
}
while($daysCount > 0) {
if(!in_array(date('w', $from), $freezeDays)) {
$daysCount--;
}
$from += C_TIME_ONE_DAY;
}
while(!in_array(date('w', $from), $deliveryDays)) {
$from += C_TIME_ONE_DAY;
}
return $from;
}
/*
* 5 дней на доставку
* Заказ, сделанный в 12:01 начинает доставляться со следующего дня
* в субботу и воскресенье заказы не движутся
* склад выдает заказы по пн,ср,чт,пт
*/
$deliveryDate = delivery(strtotime('2016-06-06 12:08'), 5, 12, [0,6], [1,3,4,5]);
echo 'warehouse: ', date('Y-m-d', $deliveryDate), PHP_EOL;
echo 'office: ', date('Y-m-d', $deliveryDate + C_TIME_ONE_DAY), PHP_EOL;
$teams = array('team1', 'team2', 'team3', 'team4');
shuffle($teams);
echo $teams[0], ' VS. ', $teams[1], PHP_EOL;
echo $teams[2], ' VS. ', $teams[3], PHP_EOL;
$row_set = array();
$i = 0;
while( $row = mysql_fetch_array( $query, MYSQL_ASSOC ) )
{
$row_set[] = $row;
$i++;
}
echo json_encode($row_set), PHP_EOL, 'count: ', $i, PHP_EOL;
/**
* Calculates whether Point is in Polygon or not. Uses mySql
* @param array $aPoint
* @param array $aCityBounds
* @return boolean
*/
protected function isPointInCity(array $aPoint,array &$aCityBounds)
{
$lPointGeomText = 'Point(' . $aPoint[0] . ' ' . $aPoint[1] . ')';
$lPolyGeomText = '';
foreach($aCityBounds as &$lBoundPoint)
$lPolyGeomText .= (empty($lPolyGeomText) ? '' : ',') . $lBoundPoint[0] . ' ' . $lBoundPoint[1];
// include first point to finish polygon
$lPolyGeomText = 'Polygon((' . $lPolyGeomText . ',' . $aCityBounds[0][0] . ' ' . $aCityBounds[0][1] . '))';
$lQuery = "SELECT MBRIntersects(GeomFromText('" . $lPolyGeomText . "'),GeomFromText('" . $lPointGeomText . "'))";
return intval(DbWrapper::dbGetValue($lQuery)) > 0 ? true : false;
}
protected function isPointInCityBoundingBox(array $aPoint, array &$aCityBoundBox)
{
return $aPoint[0] >= $aCityBoundBox['minx'] && $aPoint[0] <= $aCityBoundBox['maxx'] &&
$aPoint[1] >= $aCityBoundBox['miny'] && $aPoint[1] <= $aCityBoundBox['maxy'];
}
/**
* Calculate if point is inside polygon, more precisely than mySql now
* @param array $aPoint
* @param array $aCityBounds
* @param array $aCityBoundBox
* @return boolean
*/
protected function isPointInCityNoSql(array $aPoint, array &$aCityBounds, array &$aCityBoundBox)
{
if(!$this->isPointInCityBoundingBox($aPoint, $aCityBoundBox))
return false;
$pj = 0;
$pk = 0;
$wrkx = 0;
$yu = 0;
$yl = 0;
$lPointsCount = count($aCityBounds);
for($pj = 0; $pj < $lPointsCount; $pj++)
{
$yu = $aCityBounds[$pj][1] > $aCityBounds[($pj + 1) % $lPointsCount][1] ? $aCityBounds[$pj][1] : $aCityBounds[($pj + 1) % $lPointsCount][1];
$yl = $aCityBounds[$pj][1] < $aCityBounds[($pj + 1) % $lPointsCount][1] ? $aCityBounds[$pj][1] : $aCityBounds[($pj + 1) % $lPointsCount][1];
if($aCityBounds[($pj + 1) % $lPointsCount][1] - $aCityBounds[$pj][1])
$wrkx = $aCityBounds[$pj][0] + ($aCityBounds[($pj + 1) % $lPointsCount][0] - $aCityBounds[$pj][0]) * ($aPoint[1] - $aCityBounds[$pj][1]) / ($aCityBounds[($pj + 1) % $lPointsCount][1] - $aCityBounds[$pj][1]);
else
$wrkx = $aCityBounds[$pj][0];
if($yu >= $aPoint[1])
if($yl < $aPoint[1])
{
if($aPoint[0] > $wrkx)
$pk++;
if(abs($aPoint[0] - $wrkx) < 0.00001)
return true;
}
if((abs($aPoint[1] - $yl) < 0.00001) && (abs($yu - $yl) < 0.00001) && (abs(abs($wrkx - $aCityBounds[$pj][0]) + abs($wrkx - $aCityBounds[($pj + 1) % $lPointsCount][0]) - abs($aCityBounds[$pj][0] - $aCityBounds[($pj + 1) % $lPointsCount][0])) < 0.0001))
return true;
}
return ($pk % 2) ? true : false;
}