文章目录

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=&quot;SELECT * FROM `book`&quot;;
// 执行sql查询
$result=mysql_db_query($mysql_database, $strsql, $conn);
// 获取查询结果
$row=mysql_fetch_row($result);

echo '&lt;font face=&quot;verdana&quot;&gt;';
echo '&lt;table border=&quot;1&quot; cellpadding=&quot;1&quot; cellspacing=&quot;2&quot;&gt;';

// 显示字段名称
echo &quot;&lt;/b&gt;&lt;tr&gt;&lt;/b&gt;&quot;;
for ($i=0; $i&lt;mysql_num_fields($result); $i++)
{
  echo '&lt;td bgcolor=&quot;#000F00&quot;&gt;&lt;b&gt;'.
  mysql_field_name($result, $i);
  echo &quot;&lt;/b&gt;&lt;/td&gt;&lt;/b&gt;&quot;;
}
echo &quot;&lt;/tr&gt;&lt;/b&gt;&quot;;
// 定位到第一条记录
mysql_data_seek($result, 0);
// 循环取出记录
while ($row=mysql_fetch_row($result))
{
  echo &quot;&lt;tr&gt;&lt;/b&gt;&quot;;
  for ($i=0; $i&lt;mysql_num_fields($result); $i++ )
  {
    echo '&lt;td bgcolor=&quot;#00FF00&quot;&gt;';
    echo $row[$i];
    echo '&lt;/td&gt;';
  }
  echo &quot;&lt;/tr&gt;&lt;/b&gt;&quot;;
}

echo &quot;&lt;/table&gt;&lt;/b&gt;&quot;;
echo &quot;&lt;/font&gt;&quot;;
// 释放资源
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

文章目录