Skip to content

Instantly share code, notes, and snippets.

@spacebit-official
spacebit-official / regParse.php
Last active November 17, 2017 00:46
regParse
<?
//парсинг с помощью регулярных выражений
$url = 'http:///';
$file = file_get_contents($url);
$pattern = '#<table class="rates-table-nbrb".+?</table>#s';
preg_match($pattern, $file, $matches);
print_r($matches);
#<body.+>(.*?)</body>#su //с учетом атрибутов
#<div[^>]+?id\s*?=\s*?["\']content["\'][^>]*?>(.+?)</div>#su
#<div[^>]+?id\s*?=\s*?(["\'])content\1[^>]*?>(.+?)</div>#su //первая ковычка ложится в карман
<?
///////////////////////////////////////////////////////////////////////////////////////////////////////////
$url = 'http://www.kolesa.ru/news/page/1';
$title = pq('title')->html();// получения по селектору
$article->find('.class:eq(3)')->text(); // 4 по счету класс
$article->find('.cat')->remove(); //удаляем нужный блок с классом
$article->find('.cat')->prepend('Категория: '); //добавляем текст в нужный блок с классом
$article->find('.cat')->wrap('<div class=category>')->after('Дата:' . date('Y-M-D')); //делаем обертку и добавляемпосле класса .cat дату
phpQuery::unloadDocuments($doc); //чистим память
$article->find('div.forecast-briefly__day:not(.forecast-briefly__day_weekstart_0)'); //кроме
@spacebit-official
spacebit-official / jqueryAjaxData.php
Last active January 12, 2018 14:59
jqueryAjaxData
<script>
////////////////////////////////////////
var a = $('input[name="var1"]').val();
var b = $('input[name="var2"]').val();
//ajax
data: {a:a,b:b},
data: 'a='+a+'&b='+b
////////////////////////////////////////
var send = {};
send['a'] = $('input[name="var1"]').val();
@spacebit-official
spacebit-official / curl.php
Last active November 17, 2017 00:44
curl
<?
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url); //http/https адрес
curl_setopt($ch, CURLOPT_NOBODY, true); //без тела
curl_setopt($ch, CURLOPT_HEADER, true); //смотреть заголовки
curl_setopt($ch, CURLOPT_COOKIE, 'cookie=777'); //отправляем куки
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_POST, 1);
@spacebit-official
spacebit-official / curl.class.php
Last active November 9, 2017 08:27
curl.class
<?php
/*
Класс для работы с Curl
Все функции для вытаскивания данных с сайта
/************************ПРИМЕНЕНИЕ********************************
//если нужна авторизация
$options['autorization']=1;
$options['after_autoriz']='my';
$options['login_page']=URL.'/login';
@spacebit-official
spacebit-official / sqlPdoClass.php
Last active November 17, 2017 00:43
sqlPdoClass
<?
class sql {
private static $instance;
private $db;
public static function app() {
if (self::$instance == null) {
self::$instance = new sql();
@spacebit-official
spacebit-official / simple_html_dom.php
Last active November 17, 2017 00:41
simple_html_dom
<?
use Sunra\PhpSimple\HtmlDomParser;
$html = curl_get('https://ntschool.ru/kursyi');
$dom = HtmlDomParser::str_get_html($html);
$courses = $dom->find('.courses-list--item-body');
<?php
$cookie = ''; //переменная нужна для сохранения печенек
function pageVK($url) {
global $cookie;
$curl = curl_init($url);
curl_setopt($curl,CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl,CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl,CURLOPT_SSL_VERIFYHOST, false);
<Files cron.php>
order deny,allow
allow from localhost
allow from youhostname
allow 123.45.67.89
</Files>
TRUNCATE TABLE %TABLE_NAME%
INSERT IGNORE INTO