Introduction: The programming notes in this article will introduce to you the relevant content about how to store the data received by php. I hope it will be helpful to you. Let’s take a look.
List of contents of this article:
- 1. How to capture webpage data and save it to the database php
- 2. PHP, how to save the form to the database and display it
- 3. How to receive the user’s id and save it to the database when the php front desk fills in the data
/li>
- 4. How does PHP receive and save dynamic data and display it on the webpage in real time?
How to capture web page data and save it to the database php
Give me an example Check it out.
if($pro_list_cOntents=@file_get_contents(”))
{
preg_match_all(“/td 50%\” valign=\ “top\”(.*)td 10\”img src=\”images\/spacer.gif\”/isU”, $pro_list_contents, $pro_list_contents_ary);
for($i=0; $icount($pro_list_contents_ary[1]); $i++)
{
preg_match_all(“/a href=\”(.*)\”img src=\”(.%20%20*)\”.*span(.*)\/span/isU”, $pro_list_contents_ary[1][$i], $url_img_price);
$url=addslashes($url_img_price[1][ 0]);
$img=str_replace(‘ ‘, ‘20%’, trim(”.$url_img_price[2][0]));
$price= (float)str_replace(‘$’, ”, $url_img_price[3][0]);
preg_match_all(“/a class=\”ml1\” href=\”.*\”( .*)\/a/isU”, $pro_list_contents_ary[1][$i], $proname_ary);
$prOname=addslashes($proname_ary[1][0]);
include(“inc/db_connections.php”);
$rs=mysql_query(“select * from pro where Url=’$url’ and CateId='{$cate_row[‘CateId’] }'”); //Whether it has been collected
if(mysql_num_rows($rs))
{
echo “Skip: {$url} br”;
continue;
}
$basedir=’/u_file/pro/img/’.date(‘H/’);
p>
$save_dir=Build_dir($basedir); //Create directory function
$ext_name = GetFileExtName( $img ); //Get the name after the image
$ SaveName = date( ‘mdHis’ ). rand( 10000, 99999 ) . ‘.’ . $ext_name;
if( $get_file=@file_get_contents( $img ) )
{
$fp = @fopen( $save_dir . $SaveName, ‘w’ );
@fwrite( $fp, $get_file );
@fclose ( $fp );
@chmod( $save_dir . $SaveName, 0777 );
@copy( $save_dir . $SaveName, $save_dir . ‘small_’.$SaveName ) ;
$imgpath=$basedir.’small_’.$SaveName;
}
else
{
p> $imgpath=”;
}
if($pro_intro_cOntents=@file_get_contents($url))
{
preg_match_all(“/\/h1(.*)\/td\/tr/isU”, $pro_intro_contents, $pro_intro_contents_ary);
$p_cOntents=addslashes(str_replace(‘src=”‘,%20’src%20%20=”‘, $pro_intro_contents_ary[1][0]));
$p_cOntents=SaveRemoteImg($p_contents, ‘/u_file/pro/intro/’.date(‘H/’)); / /Save the picture in the remote html code locally
}
$t=time();
mysql_query(“insert into pro(CateId, ProName , PicPath_0, S_PicPath_0, Price_0, Contents, AddTime, Url) values(‘{$cate_row[‘CateId’]}’, ‘$proname’, ‘$imgpath’, ‘$img’, ‘$price’, ‘$p_contents ‘, ‘$t’, ‘$url’)”);
echo $url.$img.$cate.”br\r\n”;
}
p>
}
PHP, how to save the form to the database and display
The first thing you can use is Jquery’s Ajax technology to operate.
The idea is this, first of all, the front-end judges the JS and submits it to the background, the code is as follows:
$(function(){
$.ajax({
type:post,
dataType:json,
url: save.php,
data:$(“input[name =x]”).val(),
success:function(data){
}
});
});
In this way, the backend connects to the database and inserts data after receiving the Ajax request
Other operations can be performed similarly.
How to receive the user’s id and save it to the database when the php front desk fills in the data
If you are right, you mean how to judge which user the user is when he submits the data after filling in the data at the front desk submitted it, right?
In fact, this problem is not a problem, because the user submits the database using a separate client, and the session of each client is independent, as long as the user id is written to $_SESSION when the user logs in [‘ user_id ‘] = $user_id; That’s it, get $_SESSION[‘user_id’] directly in the database, which is the user id you need.
Generally speaking, some commonly used and global data can be stored in the session for calling.
How does PHP receive dynamic data and save it and display it on the web page in real time?
The header is added with timeout control, but it is invalid for many servers, because the server output timeout is mostly controlled by the server, so it is recommended to use cmd scriptRun this program by way:
?php
set_time_limit(0); //Disable script timeout
// Create the socket and connect
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
$connection = socket_connect($socket,’116.236.128.220′, 14580);
/ /Write some test data to our socket
if(!socket_write($socket, “user NoCall pass -1 vers test 1.0 filter b/B* \r\n”))
{
echo(“pWrite failed/p”);
}
if(!file_exists(‘socket_log.html’)){
file_put_contents(‘socket_log.html’, ‘script
var xx = setInterval(function(){ //Refresh the page every 5 seconds
window.location.reload ();
}, 5000);
/script’);
}
// Read any response from the socket
while($buffer = socket_read($socket, 64, PHP_NORMAL_READ))
{
echo json_encode($buffer); //Convert to json data Output
//Enter the file
file_put_contents(‘socket_log.html’, json_encode($buffer), FILE_APPEND);
}
echo(“pDone Reading from Socket/p”);
How to use: Run this script with the command line
php script.php
Script It will run until the end of receiving data, and continue to write the received data to the socket_log.html file.
Open the socket_log.html page in the browser, this page will automatically refresh every 5 seconds to display the latest data.
Ensure that the program has permission to create and write socket_log.html files
Conclusion: The above is all the content of how the data received by php is stored for everyone in the programming notes, thank you Take the time to read the content of this site, I hope it will be helpful to you, don’t forget to search for more information about how to store the data received by php on this site.