4 ноября 2012
Нет комментариев
$opts=array('http'=>array('proxy'=>'proxy_adress:proxy_port','request_fulluri'=>true)); $context=stream_context_create($opts); $data=file_get_html('http://site.ru/',false,$context);
$opts=array('http'=>array('proxy'=>'proxy_adress:proxy_port','request_fulluri'=>true)); $context=stream_context_create($opts); $data=file_get_html('http://site.ru/',false,$context);
Для парсинга используя PHP Simple HTML DOM Parser
с указанием cookies.
$opts=array('http'=>array('method'=>"GET",'header'=>"Accept-language: en\r\n"."Cookie: cookie_name=cookie_value\r\n",'user_agent'=>'Mozilla/5.0 (Macintosh; U; PPC Mac OS X 10.4; en-US; rv:1.9.2.28) Gecko/20120306 Firefox/3.6.28')); $context=stream_context_create($opts); $data=file_get_html('http://site.ru/',false,$context);
<?php echo do_shortcode('[contact-form-7 id="259" title="Форма для контакта 1"]'); ?>
Изменение БД:
Добавляем поля в таблицу wp_posts
Добавление полей в форму редактирования записи:
/wp-admin/edit-form-advanced.php
например после div с заголовком:
<input type="text" name="post_title" size="30" tabindex="1" value="<?php echo esc_attr( htmlspecialchars( $post->post_title ) ); ?>" id="title" autocomplete="off" />
Сохранение указанных значений:
/wp-includes/post.php
изменения вносятся в функцию wp_insert_post
(добавляем свои поля в массив)
$data = compact( array( 'post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_content_filtered', 'post_title', 'post_excerpt', 'post_status', 'post_type', 'comment_status', 'ping_status', 'post_password', 'post_name', 'to_ping', 'pinged', 'post_modified', 'post_modified_gmt', 'post_parent', 'menu_order', 'guid' ) );
$arr = array(2, 3, 4, 2, 5, 2); function delEl($arr, $del) { foreach($arr as $val) { if($val !== $del) $newArr[] = $val; } return $newArr; } // Пример $checkDelEl = delEl($arr, 2); print_r($checkDelEl); // Array ( [0] => 3 [1] => 4 [2] => 5 )
src всех изображений:
preg_match_all('/<img[^>]+src=([\'"])?((?(1).+?|[^\s>]+))(?(1)\1)/',$content,$matches); print_r($matches[2]);
Как пример:
if ($matches[2][0]!='') { echo "<img src='".$matches[2][0]."' alt=''/>"; }
Получить домен из URL:
parse_url($url,PHP_URL_HOST)