>백엔드 개발 >PHP 튜토리얼 >PHP乱入,post,mysql连接,抓取网页_PHP教程

PHP乱入,post,mysql连接,抓取网页_PHP教程

WBOY
WBOY원래의
2016-07-13 10:37:23878검색

post

<?php
header("content-type:text/html; charset=utf-8");
include ("util/HttpClient.class.php");
$params = array(
    'usrname' => '0',
    'pwd' => '1',
);
/*
$pageContents = HttpClient::quickPost('http://xxxxxxxxx',$params);
echo $pageContents;*/
$client = new HttpClient('xxxxxx');
$client->setDebug(true);
$client->post('/action',$params);
echo $client->getContent();
// foreach (json_decode($client->getContent(), true) as $item)
//		echo $item['name'].'<br>';


?><?php
header("content-type:text/html; charset=utf-8");
include ("util/HttpClient.class.php");
$params = array(
    'usrname' => '0',
    'pwd' => '1',
);
/*
$pageContents = HttpClient::quickPost('http://xxxxxxxxx',$params);
echo $pageContents;*/
$client = new HttpClient('xxxxxx');
$client->setDebug(true);
$client->post('/action',$params);
echo $client->getContent();
// foreach (json_decode($client->getContent(), true) as $item)
//		echo $item['name'].'<br>';


?>

mysql连接:

<?php
    echo "This is a test</br>"; 
    echo "asdfasdfadsf";
    $mysql_server_name="xxxxx"; //数据库服务器名称
    $mysql_username="root"; // 连接数据库用户名
    $mysql_password="root"; // 连接数据库密码
    $mysql_database="bookshop"; // 数据库的名字
    
    // 连接到数据库
    $conn=mysql_connect($mysql_server_name, $mysql_username,
                        $mysql_password);
                        
     // 从表中提取信息的sql语句
    $strsql="SELECT * FROM `book`";
    // 执行sql查询
    $result=mysql_db_query($mysql_database, $strsql, $conn);
    // 获取查询结果
    $row=mysql_fetch_row($result);
    
     
    echo '<font face="verdana">';
    echo '<table border="1" cellpadding="1" cellspacing="2">';

    // 显示字段名称
    echo "</b><tr></b>";
    for ($i=0; $i<mysql_num_fields($result); $i++)
    {
      echo '<td bgcolor="#000F00"><b>'.
      mysql_field_name($result, $i);
      echo "</b></td></b>";
    }
    echo "</tr></b>";
    // 定位到第一条记录
    mysql_data_seek($result, 0);
    // 循环取出记录
    while ($row=mysql_fetch_row($result))
    {
      echo "<tr></b>";
      for ($i=0; $i<mysql_num_fields($result); $i++ )
      {
        echo '<td bgcolor="#00FF00">';
        echo $row[$i];
        echo '</td>';
      }
      echo "</tr></b>";
    }
   
    echo "</table></b>";
    echo "</font>";
    // 释放资源
    mysql_free_result($result);
    // 关闭连接
    mysql_close($conn);  
?>

抓取网页:

<?php 
header("content-type:text/html; charset=gbk");
$url='http://ipanda3.taobao.com/'; 
$lines_string=file_get_contents($url); 
echo $lines_string; 

抓取网页某个元素,使用simple_html_dom:



www.bkjia.comtruehttp://www.bkjia.com/PHPjc/735875.htmlTechArticlepost '0', 'pwd' => '1',);/*$pageContents = HttpClient::quickPost('http://xxxxxxxxx',$params);echo $pageContents;*/$client = new HttpClient('xxxxxx');$client->setDebug(true);$client...
성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.