Regular expressions are used to obtain the webpage source code keyword and description.

Source: Internet
Author: User
Obtain the webpage source code keyword and description in regular expressions. The problem is:

 
 


Scenario 2:

 
 



Note: it may be case sensitive, and there is name, which is different from the content attribute [color = # FF6600]. [/color]

The younger brother tried to write it. he could only match one webpage and did not know what the problem was. Thank you!
Keyword:

 1.preg_match("/
 
  tmpHtml,$inarr); 2.preg_match("/
  
   tmpHtml,$inarr2);
  
 
1.preg_match("/
 
  tmpHtml,$inarr);2.preg_match("/
  
   tmpHtml,$inarr2);
  
 

Note: Some webpages can match and some cannot.


Reply to discussion (solution)

By the way, I forgot to explain that some Web pages are like this:




Keywords and description do not have double quotation marks. No match. I hope you can help me improve it. it is best to pass the test.

Isn't there a get_meta_tags function?

Isn't there a get_meta_tags function?
+ 1, you can return an array of meta, and then extract the required

Haha, that's funny. thank you! foolbirdflyfirst yangball

Name is above:

 
  
   
    
   
  
 


The name is later:

  
   
    
    
   
  
 

Name is above:

 
  
   
    
   
  
 

The name is later:

 
  
   
    
   
  
 

Based on the upstairs, we can further conclude that:
Name in front:

<(\s*)(meta|META|Meta)(\s*)(name|NAME|Name)=(\'|\"|)(keywords|KEYWORDS|Keywords)(\'|\"|)(\s*)(content|CONTENT|Content)=(\'|\"|)(.*)(\'|\"|)(\s*)><(\s*)(meta|META|Meta)(\s*)(name|NAME|Name)=(\'|\"|)(keywords|KEYWORDS|Keywords)(\'|\"|)(\s*)(content|CONTENT|Content)=(\'|\"|)|(\'|\"|)(\s*)><(\s*)(meta|META|Meta)(\s*)(name|NAME|Name)=(\'|\"|)(description|DESCRIPTION|Description)(\'|\"|)(\s*)(content|CONTENT|Content)=(\'|\"|)(.*)(\'|\"|)(\s*)><(\s*)(meta|META|Meta)(\s*)(name|NAME|Name)=(\'|\"|)(description|DESCRIPTION|Description)(\'|\"|)(\s*)(content|CONTENT|Content)=(\'|\"|)|(\'|\"|)(\s*)>

After name:

<(\s*)(meta|META|Meta)(\s*)(content|CONTENT|Content)=(\'|\"|)(.*)(\'|\"|)(\s*)(name|NAME|Name)=(\'|\"|)(keywords|KEYWORDS|Keywords)(\'|\"|)(\s*)><(\s*)(meta|META|Meta)(\s*)(content|CONTENT|Content)=(\'|\"|)|(\'|\"|)(\s*)(name|NAME|Name)=(\'|\"|)(keywords|KEYWORDS|Keywords)(\'|\"|)(\s*)><(\s*)(meta|META|Meta)(\s*)(content|CONTENT|Content)=(\'|\"|)(.*)(\'|\"|)(\s*)(name|NAME|Name)=(\'|\"|)(description|DESCRIPTION|Description)(\'|\"|)(\s*)><(\s*)(meta|META|Meta)(\s*)(content|CONTENT|Content)=(\'|\"|)|(\'|\"|)(\s*)(name|NAME|Name)=(\'|\"|)(description|DESCRIPTION|Description)(\'|\"|)(\s*)>

The above is the regular expression to get the webpage source code keyword and description. it is a bit painful. For more information, please follow the PHP Chinese network (www.php1.cn )!

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.