Home php教程 php手册 济南网站建设中如何使用php自动获取文章内容关键字

济南网站建设中如何使用php自动获取文章内容关键字

Jun 13, 2016 am 09:37 AM
web development Enterprise security information Technology security software database mobile development system security Website security cyber security network technology software development

        济南网站建设中 了解网站的优化的人员都很清楚,对于一个网站来说,网站内部结构的优化对于搜索引擎蜘蛛的爬行起到一个决定性的作用。网站内部优化的越好搜索引擎蜘蛛爬行 的深度和时间也就越长和越深。淡然蜘蛛爬行的规律还有很多因素的影响,比如网站权重,网站内容质量,蜘蛛类型等,都会决定网站爬行的深度问题。

        怎么样才算是网站内部优化的好呢,网站内部优化可分为两个部分,一是网站内部代码的优化,这其中包括html标签的使用规范,DIV+CSS的使用优化技 巧两方面。二是网站结构的优化,网站结构优化归根到底就是能够让网站的内部结构符合人们的浏览习惯,能够在网站浏览者对网站的任何一个页面进行浏览的时候 都能够快速方便的找到自己喜欢的东西。

        我们进入正题,想要提高网站的内部结构,让浏览者在适当的位置,找到适当的有效信息。在网站中的文章增加自动获取关键字的功能就成为了一个很好的选择。试 想,当你对网站中的一篇文章进行浏览的时候,在文章的最后,有本文相关关键字,本问相关搜索等信息的话,既有可能你会接着往下看和本文相关的内容,从而降 低了网站的跳出率,提高了网能浏览性。

网站文章内容关键字自动获取

一、文章内容关键字自动获取的思路

        通过获取php获取到所需提取的内容,通过字典中定义的分词方法,对获取到的内容进行分词,最后将得到的分次进行最终匹配,将最终得到的结果以数组的形式返回给函数。

二、文章内容关键字自动获取实现方法

        首先我们把已经写好的字典文件和分次函数以及测试文件下载到本地,然后打开其中的index.php文件,把其中的 //print_r(get_tags_arr($con));这行代码的注视删掉,运行此文件,查看是否有分次输出。正常输出结果如下图所示。

内容自动获取关键字测试结果

通过图可以看到,只需要使get_tags_arr这个函数得到我们所需要的分次的文字就可以了,代码中的实现方法:

$a=trim(strip_tags(content('jianjie'))); //得到所需要提取关键字的文字部分并去除文字中的html标签和空格标签

$arr=get_tags_arr($a); // 使用get_tags_arr函数将文字进行分词处理,并返回数组

foreach($arr as $k=>$val){

echo "$val ";

}

//通过foreach将数组循环,并输出html格式

?>

通过以上步骤就会发现我们已经得到自己想要的分词结果,就是这么简单,文章内容自动获取关键字的功能就完成了。

三、文章内容自动获取关键字常见错误

①、分词关键字中出现html标签

解决方法:在输出内容之前加入strip_tags()函数,将输出内容中的html标签去除。

②、输出字符中出现乱码

解决方法:将分词在输出之前进行转码处理,所使用函数mb_convert_encoding()。

浏览器乱码现象

③、在不同浏览器中,分词转码之后,会发生乱码现象

解决方法:通过判断浏览器的类型,设置是否需要对分词进行转码处理,所使用函数strpos($_SERVER['HTTP_USER_AGENT']。

浏览器判断和转码处理

        在进行济南网站建设的 过程中,我们需要对客户进行网站建设的工作时,要记住尽可能的把网站的每个细节都处理好,其实像网站内容自动提取关键字这个功能,对于一般性的网站来说都 是可有可无的,甚至在实际中不加入这个功能对网站正常开发和运营都没有什么影响,但是考虑到网站用户体验上来说,适当的加入类似这样的功能,在很大程度上 有助于提高网站的可读性和吸引力,从而提高了网站的权重和关键字的排名。

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1669
14
PHP Tutorial
1273
29
C# Tutorial
1256
24
iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos Jul 18, 2024 am 05:48 AM

Apple's latest releases of iOS18, iPadOS18 and macOS Sequoia systems have added an important feature to the Photos application, designed to help users easily recover photos and videos lost or damaged due to various reasons. The new feature introduces an album called "Recovered" in the Tools section of the Photos app that will automatically appear when a user has pictures or videos on their device that are not part of their photo library. The emergence of the "Recovered" album provides a solution for photos and videos lost due to database corruption, the camera application not saving to the photo library correctly, or a third-party application managing the photo library. Users only need a few simple steps

How to save JSON data to database in Golang? How to save JSON data to database in Golang? Jun 06, 2024 am 11:24 AM

JSON data can be saved into a MySQL database by using the gjson library or the json.Unmarshal function. The gjson library provides convenience methods to parse JSON fields, and the json.Unmarshal function requires a target type pointer to unmarshal JSON data. Both methods require preparing SQL statements and performing insert operations to persist the data into the database.

MySQL: Simple Concepts for Easy Learning MySQL: Simple Concepts for Easy Learning Apr 10, 2025 am 09:29 AM

MySQL is an open source relational database management system. 1) Create database and tables: Use the CREATEDATABASE and CREATETABLE commands. 2) Basic operations: INSERT, UPDATE, DELETE and SELECT. 3) Advanced operations: JOIN, subquery and transaction processing. 4) Debugging skills: Check syntax, data type and permissions. 5) Optimization suggestions: Use indexes, avoid SELECT* and use transactions.

PHP Database Connection Pitfalls: Avoid Common Mistakes and Misunderstandings PHP Database Connection Pitfalls: Avoid Common Mistakes and Misunderstandings Jun 05, 2024 pm 10:21 PM

To avoid PHP database connection errors, follow best practices: check for connection errors and match variable names with credentials. Use secure storage or environment variables to avoid hardcoding credentials. Close the connection after use to prevent SQL injection and use prepared statements or bound parameters.

PHP's Current Status: A Look at Web Development Trends PHP's Current Status: A Look at Web Development Trends Apr 13, 2025 am 12:20 AM

PHP remains important in modern web development, especially in content management and e-commerce platforms. 1) PHP has a rich ecosystem and strong framework support, such as Laravel and Symfony. 2) Performance optimization can be achieved through OPcache and Nginx. 3) PHP8.0 introduces JIT compiler to improve performance. 4) Cloud-native applications are deployed through Docker and Kubernetes to improve flexibility and scalability.

HTML, CSS, and JavaScript: Essential Tools for Web Developers HTML, CSS, and JavaScript: Essential Tools for Web Developers Apr 09, 2025 am 12:12 AM

HTML, CSS and JavaScript are the three pillars of web development. 1. HTML defines the web page structure and uses tags such as, etc. 2. CSS controls the web page style, using selectors and attributes such as color, font-size, etc. 3. JavaScript realizes dynamic effects and interaction, through event monitoring and DOM operations.

The Future of HTML, CSS, and JavaScript: Web Development Trends The Future of HTML, CSS, and JavaScript: Web Development Trends Apr 19, 2025 am 12:02 AM

The future trends of HTML are semantics and web components, the future trends of CSS are CSS-in-JS and CSSHoudini, and the future trends of JavaScript are WebAssembly and Serverless. 1. HTML semantics improve accessibility and SEO effects, and Web components improve development efficiency, but attention should be paid to browser compatibility. 2. CSS-in-JS enhances style management flexibility but may increase file size. CSSHoudini allows direct operation of CSS rendering. 3.WebAssembly optimizes browser application performance but has a steep learning curve, and Serverless simplifies development but requires optimization of cold start problems.

JavaScript: Exploring the Versatility of a Web Language JavaScript: Exploring the Versatility of a Web Language Apr 11, 2025 am 12:01 AM

JavaScript is the core language of modern web development and is widely used for its diversity and flexibility. 1) Front-end development: build dynamic web pages and single-page applications through DOM operations and modern frameworks (such as React, Vue.js, Angular). 2) Server-side development: Node.js uses a non-blocking I/O model to handle high concurrency and real-time applications. 3) Mobile and desktop application development: cross-platform development is realized through ReactNative and Electron to improve development efficiency.

See all articles