Php self-writing function code obtains the keyword to hyperlink
Source: Internet
Author: User
Retrieving keywords based on weights removes hyperlinks in articles. simple and concise
1. get keywords based on weights
The code is as follows:
Function getkey ($ contents ){
$ Rows = strip_tags ($ contents );
$ Arr = array ('','', "\ s", "\ r \ n", "\ n", "\ r", "\ t ", ">", "", "");
$ Qc_rows = str_replace ($ arr, '', $ rows );
If (strlen ($ qc_rows) & gt; 2400 ){
$ Qc_rows = substr ($ qc_rows, '0', '123 ');
}
$ Data = @ implode ('', file (" http://keyword.discuz.com/related_kw.html? Title = $ contents & ics = gbk & ocs = gbk "));
Preg_match_all ("/ (. *) A \ [(. *) \] (. *)> <\/kw>/", $ data, $ out, PREG_SET_ORDER );
For ($ I = 0; $ I <5; $ I ++ ){
$ Key = $ key. $ out [$ I] [2];
If ($ out [$ I] [2]) $ key = $ key .",";
}
Return $ key;
}
// $ Contents the article for you to get the keyword
2. removing hyperlinks in the article is simple and concise
The code is as follows:
Function get_new_content ($ content ){
Include ("../simple_html_dom.php ");
$ Html = str_get_html ($ content );
$ A_href = $ html-> find ('A ');
Foreach ($ a_href as $ link ){
$ Text = $ link-> plaintext; // text in the link;
$ Link-> outertext = $ text;
}
$ Now_content = $ html-> save ();
}
// Preg_replace ("/(.*?) <\/A>/I "," \ $ {1} ", $ content); you can also use regular expressions.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service