In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces "how to use PHP to achieve the release of Weibo programs". In daily operation, I believe many people have doubts about how to use PHP to publish Weibo programs. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts about "how to use PHP to publish Weibo programs". Next, please follow the editor to study!
First of all, we need to prepare a data table, which is structured as follows:
CREATE TABLE `say` (`id` int (11) NOT NULL auto_increment, `userid` int (11) NOT NULL default '0mm, `content` varchar (200) NOT NULL, `addtime` int (10) NOT NULL, PRIMARY KEY (`id`) ENGINE=MyISAM DEFAULT CHARSET=utf8
Note that in this example, the time field: addtime is set to int for the convenience of subsequent time processing. In many applications (such as Discuz forums), the time type is converted to digital.
Timeline processing function and formatted output list function: timeline processing function, that is, to convert the time into the forms we see, such as "5 minutes ago", "10:21 yesterday" and so on. You can see the article I wrote before: PHP implements the timeline function with the code as follows:
/ * time conversion function * / function tranTime ($time) {$rtime = date ("Mmurd Hrtime I", $time); $htime = date ("HRV I", $time); $timetime = time ()-$time; if ($time)
< 60) { $str = '刚刚'; } else if ($time < 60 * 60) { $min = floor($time/60); $str = $min.'分钟前'; } else if ($time < 60 * 60 * 24) { $h = floor($time/(60*60)); $str = $h.'小时前 '.$htime; } else if ($time < 60 * 60 * 24 * 3) { $d = floor($time/(60*60*24)); if($d==1) $str = '昨天 '.$rtime; else $str = '前天 '.$rtime; } else { $str = $rtime; } return $str; } 格式化输出函数是将得到的用户信息和发布内容及时间按照一定的格式输出到前端页面的函数,代码如下: function formatSay($say,$dt,$uid){ $say=htmlspecialchars(stripslashes($say)); return'Demo_'.$uid.''. Preg_replace ('/ ((?: http | https | ftp):\ /\ / (?: [A-Z0-9] [A-Z0-9 steps -] *) (?:\. [A-Z0-9] [A-Z0-9 cycles -] *) +):? (\ d +)?\ /? [^\ s\ "\'] +) / ispeak,'$1 million.
'.trantime ($dt).';}
Put both of the above functions into function.php, ready to be called at any time.
Submit.php handles form data
In the previous article, we knew that jQuery submitted the data obtained from the front end to the background submit.php through Ajax in the form of POST. So submit is to complete all the follow-up tasks. Please look at the code:
Require_once ('connect.php'); / / database connection file require_once (' function.php'); / / function call file $txt=stripslashes ($_ POST ['saytxt']); / / get submitted data $txt=mysql_real_escape_string (strip_tags ($txt), $link); / / filter the HTML tag and escape the special character if (mb_strlen ($txt) 140) die ("0") / / determine whether the number of input characters meets the requirements $timetime=time (); / / get the current time $userid=rand (0Magne4); / / insert data into the data table $query=mysql_query ("insert into say (userid,content,addtime) values ('$userid','$txt','$time')"); if (mysql_affected_rows ($link)! = 1) die ("0"); echo formatSay ($txt,$time,$userid); / / call the function to output the result
Note that in this example, the user ID (userid) is randomly processed for demonstration purposes, and the actual application is to get the current user's ID. In addition, you can write a database connection file by yourself. it is also available in the download DEMO provided by me.
* go back to the front-end page index.php. Index.php not only provides input entry, but also undertakes the results returned by background processing, and displays the data already in the database. The code is as follows:
140 tell me what you are doing.
At this point, this example from the front-end interaction to the background processing program, all completed, interested students do it themselves, can learn from the fun.
At this point, on the "how to use PHP to achieve the release of Weibo program" study is over, I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.