This article introduces the keyword, title, and webpage description code for php regular expressions. For more information, see. This article introduces the keyword, title, and webpage description code for php regular expressions. For more information, see.
Script ec (2); script
Get keywords
| The Code is as follows: |
|
|
Function get_keywords ($ html)
{
$ Html = strtolower ($ html );
Preg_match ("@ ] *> (.*?)@ Si ", $ html, $ regs );
$ Headdata = $ regs [1];
Preg_match ("/ "] +) [" ']? /I ", $ headdata, $ res );
If (isset ($ res )){
$ Keywords = $ res [1];
}
If ($ keywords = "") $ keywords = "NONE ";
$ Keywords = maid (textcut ($ keywords, 250 ));
$ Keywords = str_replace ("-", $ keywords );
$ Keywords = str_replace (",", $ keywords );
$ Keywords = str_replace ("", $ keywords );
$ Keywords = str_replace ("|", $ keywords );
$ Keywords = str_replace (",", $ keywords );
$ Keywords = str_replace (",", $ keywords );
$ Keywords = str_replace ("<", "", $ keywords );
$ Keywords = str_replace (">", "", $ keywords );
Return addslashes (trim ($ keywords ));
}
|
Get title
| The Code is as follows: |
|
|
Function get_title ($ html)
{
$ Html = strtolower ($ html );
$ Title = str_replace ("-", cut ($ html ,"",""));
// If ($ title = "") $ title = "No title ";
If ($ title) $ title = replace_word (textcut ($ title, 80 ));
If ($ title) $ title = preg_replace ("/<(. *?)> /"," ", $ Title );
Return addslashes (trim ($ title ));
} |
Get webpage description
| The Code is as follows: |
|
|
Function get_description ($ html)
{
$ Html = strtolower ($ html );
Preg_match ("@ ] *> (.*?)@ Si ", $ html, $ regs );
$ Headdata = $ regs [1];
Preg_match ("/ "] +) [" ']? /I ", $ headdata, $ res );
If (isset ($ res )){
$ Description = $ res [1];
}
If ($ description = "") $ description = "NONE ";
$ Description = replace_word (textcut ($ description, 250 ));
$ Description = str_replace ("-", $ description );
$ Description = str_replace (",", $ description );
$ Description = str_replace ("", $ description );
$ Description = str_replace ("|", $ description );
$ Description = str_replace (",", $ description );
$ Description = str_replace (",", $ description );
$ Description = str_replace ("<", "", $ description );
$ Description = str_replace (">", "", $ description );
Return addslashes (trim ($ description ));
} |