var someObj = {a:1,b:2};
var xhr = new XMLHttpRequest();
xhr.open('POST', 'scratch.php');
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhr.send('param=' + JSON.stringify(someObj));
xhr.onreadystatechange = function()
{
if (this.readyState == 4)
{
if (this.status == 200)
{
console.log(xhr.responseText);
}
else
{
console.log('ajax error');
}
}
};
$param = json_decode($_REQUEST["param"]);
$result = "Результат: a = ".$param->a."; b = ".$param->b;
die($result);
У меня вот так сделано в background.js:
var rootItem, translateItem;
function createContextMenu()
{
....
rootItem = chrome.contextMenus.create
(
{
id: "utilsExtRootMenuItem",
title: "Утилиты",
contexts: ["all"]
},
function(){}
);
translateItem = chrome.contextMenus.create
(
{
id: "utilsExtTranslateMenuItem",
parentId: rootItem,
title: "Перевести...",
contexts: ["all"],
onclick: translateWithWordReference
},
function(){}
);
....
}
function translateWithWordReference()
{
....
}
createContextMenu();
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title></title>
<style>
.divItem
{
width: 200px;
height: 50px;
text-align: center;
border: 1px solid darkgray;
border-radius: 5px;
cursor: pointer;
}
.active
{
background-color: green;
}
</style>
</head>
<body>
<div class="divItem" id="item1">Item1</div>
<div class="divItem" id="item2">Item2</div>
<div class="divItem" id="item3">Item3</div>
<div class="divItem" id="item4">Item4</div>
</body>
<script type="text/javascript" src ="http://localhost/Script/js/jQuery/jquery-1.11.2.min.js">
</script>
<script type="text/javascript">
var funcHandlers = {};
function intervalHandle(id)
{
delete funcHandlers[id];
$('.divItem').removeClass('active');
$('#' + id).addClass('active');
}
function mouseIn(event)
{
var funcHandler = setTimeout(intervalHandle, 1000, $(this).attr('id'));
funcHandlers[$(this).attr('id')] = funcHandler;
}
function mouseOut(event)
{
$('.divItem').removeClass('active');
clearTimeout(funcHandlers[$(this).attr('id')]);
delete funcHandlers[$(this).attr('id')];
}
$(document).ready(function()
{
$('.divItem').bind('mouseenter', mouseIn);
$('.divItem').bind('mouseleave', mouseOut);
});
</script>
</html>
$testStr = '<tr>
<td height="20"><a title="Замена кнопки Home" href="/V-iPhone-ne-rabotaet-knopka-Home">Замена кнопки HOME</a></td>
<td align="center"><span id="id169-iphone-5-home">1200</span></td>
<td align="center">от 30 минут</td>
<td align="center">3 месяца</td>
</tr>
<tr>
<td height="20"><a title="Ремонт кнопки блокировки" href="/Ne-rabotaet-knopka-vkliucheniia">Замена кнопки включения</a></td>
<td align="center"><span id="id166-iphone-5-power">1400</span></td>
<td align="center">от 30 минут</td>
<td align="center">3 месяца</td>
</tr>';
$regExpWrapper = "#<span(?:.*?)\"id(.*?)\-#si";
preg_match_all($regExpWrapper, $testStr, $matches);
print_r($matches);
<!DOCTYPE HTML>
<html>
</head>
<body>
<div id="answerPlace"></div>
</body>
<script type="text/javascript" src ="js/jquery-1.11.2.min.js"></script>
<script type="text/javascript">
var myArray = [2, 23, 54, 79, 27, 99, 14];
var url = 'http://page-izbranni.php';
var answer;
$(document).ready(function()
{
$.ajax
({
url: url,
data:
{
checks: JSON.stringify(myArray)
},
success: function(response)
{
$('#answerPlace').children().remove();
$('#answerPlace').append(response);
},
error: function(error)
{
console.log('Ошибка');
console.log(error);
}
});
});
</script>
</html>
if(isset($_REQUEST['checks']))
{
echo "<pre>";
print_r(json_decode($_REQUEST['checks']));
echo "</pre>";
}
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="content-type" content="text/html" />
<title>Player Demo</title>
<style>
.container
{
width: 1200px;
}
.content
{
width: 100px;
height: 100px;
display: block;
margin: 10px;
position: absolute;
background-color: red;
}
.readmore
{
position: absolute;
display: none;
margin: 10px;
width: 100px;
height: 50px;
background-color: green;
}
</style>
</head>
<body>
<div class="container">
<div class="content" id="1">1</div>
<div class="content" id="2">2</div>
<div class="content" id="3">3</div>
<div class="content" id="4">4</div>
<div class="content" id="5">5</div>
<div class="content" id="6">6</div>
<div class="content" id="7">7</div>
<div class="content" id="8">8</div>
<div class="content" id="9">9</div>
<div class="readmore" id="q1">1</div>
<div class="readmore" id="q2">2</div>
<div class="readmore" id="q3">3</div>
<div class="readmore" id="q4">4</div>
<div class="readmore" id="q5">5</div>
<div class="readmore" id="q6">6</div>
<div class="readmore" id="q7">7</div>
<div class="readmore" id="q8">8</div>
<div class="readmore" id="q9">9</div>
</div>
</body>
<script type="text/javascript" src ="js/jquery-1.11.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function()
{
var offsetX = 120,
offsetY = 10;
$('.content').each(function(index, item)
{
$(item).css({left: offsetX * index, top: offsetY});
$('.readmore[id=q' + (index + 1) + ']')
.css({left: offsetX * index, top: offsetY + 110});
});
$('.content').bind('mouseover', showDivContent);
$('.content').bind('mouseleave', hideDivContent);
});
function showDivContent(event)
{
$('.readmore[id=q' + $(this).attr('id') + ']')
.css({'display': 'block'});
}
function hideDivContent(event)
{
$('.readmore[id=q' + $(this).attr('id') + ']')
.css({'display': 'none'});
}
</script>
</html>
$testStr = "Lorem Ipsum - это текст-рыба, часто используемый в печати и вэб-дизайне.
Lorem Ipsum является стандартной рыбой для текстов на латинице с начала XVI века.
В то время некий безымянный печатник создал большую коллекцию размеров
и форм шрифтов, используя Lorem Ipsum для распечатки образцов.
<!--Tbegin-->something.jpg</!--Tbegin-->
Lorem Ipsum не только успешно пережил без заметных изменений пять веков,
но и перешагнул в электронный дизайн. Его популяризации в новое время послужили
публикация листов Letraset с образцами Lorem Ipsum в 60-х годах и, в более
недавнее время, программы электронной вёрстки типа Aldus PageMaker, в
шаблонах которых используется Lorem Ipsum.";
$regExp = "#(?<=<!--Tbegin-->)((?:.*?)(?:</!--Tbegin-->))#si";
echo preg_replace($regExp, "", $testStr);
something.jpg!--Tbegin-->
<!--Tbegin-->....</!--Tbegin-->
$regExp = "#((?:<!--Tbegin-->)(?:.*?)(?:</!--Tbegin-->))#si";
<?php
$link = "http://www.teleguide.info/kanal100055_20160413.html";
$page = file_get_contents($link);
$regExpWrapper = "#(?:<div id=\"programm\">)(.*?)(?:<div id=\"programm_up\">)#si";
preg_match_all($regExpWrapper, $page, $matches);
echo iconv("UTF-8", "CP1251", $matches[1][0]);
?>
<?php
$token = '';
$wall = file_get_contents("http://api.vk.com/method/wall.get?v=5.7&filter=all&domain=achan&count=1000");
$postAmount = count($wall->response->items);
$counter = 1;
$currentTime = new DateTime("now");
foreach($wall->response->items as $currentItem)
{
$postDate = new DateTime(date("Y-m-d H:i:s", $currentItem->date));
$interval = $currentTime->diff($postDate);
if($interval->d >= 1)
{
echo $counter.". Нужно удалить\t".$postDate->format("Y-m-d H:i:s")."\n";
}
else
{
echo $counter.". Пока оставляем\t".$postDate->format("Y-m-d H:i:s")."\n";
}
$counter++;
}
?>
var playListWrapper = {playlist: new Array()};
VK.api('audio.get', {https: '1', v:'5.45', count:2}, function(audio)
{
audio.response.items.forEach(function(item)
{
playListWrapper.playlist.push
({
//'icon': item.iconImage,
'title': item.artist + ' - ' + item.title,
'file': item.url
});
});
playList();
});
function playList()
{
console.table(playListWrapper.playlist);
AP.init(playListWrapper);
}
$testStr = '<tr onclick="ccl(152, 93, 56, 1)">
<td class="bj"><div class="pa labpad1"><a href="http://site.ru" onclick="return fco(152)"></a><div class="pc"><div class="ca">Name</div></div></div></td>
<td class="bi">1 <small>BTC</small></td>
<td class="bi">10 826.3640 <small>Random text</small></td>
<td class="ar arp" title="Title">161 608</td>
</tr>';
$regExpWrepper =
"#class=\"ca\">(.*?)<(?:.*?)<td(?:.*?)</td>".
"(?:.*?)class=\"bi\">(.*?)<".
"(?:.*?)title(?:.*?)>(.*?)<".
"#si";
preg_match_all($regExpWrepper, $testStr, $matches, PREG_SET_ORDER);
echo trim($matches[0][1]).", ".trim($matches[0][2]).", ".trim($matches[0][3])."\n";
<?php
function getRemoteData($url, $argsArray, $ifPostRequest)
{
$userAgent = "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2414.0 Safari/537.36";
$cURLsession = curl_init();
curl_setopt($cURLsession, CURLOPT_URL, $url);
curl_setopt($cURLsession, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($cURLsession, CURLOPT_RETURNTRANSFER, true);
curl_setopt($cURLsession, CURLOPT_USERAGENT, $userAgent);
curl_setopt($cURLsession, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($cURLsession, CURLOPT_CONNECTTIMEOUT, 30);
// curl_setopt($cURLsession, CURLOPT_REFERER, $url);
if($ifPostRequest)
{
curl_setopt($cURLsession, CURLOPT_POST, true);
curl_setopt($cURLsession, CURLOPT_POSTFIELDS, $argsArray);
curl_setopt($cURLsession, CURLOPT_HTTPHEADER,
array
(
"X-Requested-With: XMLHttpRequest"
));
}
if(($curlResult = curl_exec($cURLsession)) === false)
{
die("Error fetchind data: ".curl_error($cURLsession)." from ".$this->url);
}
curl_close($cURLsession);
return $curlResult;
}
$url = "http://toto.fonsportsbet.com/list/ru/322/";
$content = getRemoteData($url, "", false);
// file_put_contents(__DIR__."\\footbal.html", $content);
// echo "Saved\n";
// $content = file_get_contents(__DIR__."\\footbal.html");
$regExpLigaWrapper =
"#(?<=<td colspan=4 class=S2L>)(.*?)(<td class=bl>)".
"(.*?)((?:<td colspan=4 class=S2L>)|(?:</table>))#si";
$regExpPlayWrapper =
"#<td>(\d{1,})<td>(.*?)<td class=S1L>(.*?)<td>".
"(.*?)<td(?:.*?)bl>(.*?)<td>(.*?)<(?:.*?)>(.*?)(?:<|$)#si";
preg_match_all($regExpLigaWrapper, $content, $ligaMatches, PREG_SET_ORDER);
foreach($ligaMatches as $ligaMatch)
{
echo "Liga: ".$ligaMatch[1]."\n****************************\n";
preg_match_all($regExpPlayWrapper, $ligaMatch[3], $playMatches, PREG_SET_ORDER);
foreach($playMatches as $playMatch)
{
echo
"id: ".$playMatch[1]."\n".
"Time: ".$playMatch[2]."\n".
"Name: ".$ligaMatch[1]."\t".$playMatch[3]."\n".
"Count: ".$playMatch[4]."\n".
"Class1: ".$playMatch[5]."\n".
"Class2: ".$playMatch[6]."\n".
"Class3: ".$playMatch[7]."\n".
"\n";
}
}
?>