php - 在 PHP 中用空格替换标签以实现 SEO 元描述

标签 php mysql tags seo meta-tags

我正在尝试将 mySQL 数据库中的 HTML 标签剥离为用于 SEO 元描述的纯文本。数据库中的 HTML 如下所示:

<p>The Break-ezee is a vital piece of equipment for anyone when breaking horses - As used by Mary King.</p>
<p></p>
<p>The Break-ezee is an all in one progressive training product for use when breaking horses.</p>

我正在使用以下 PHP 对其进行格式化:

$showseodesc = trim(strip_tags(substr($showseoproduct['text'],0,160)));

这显示了网站源代码中的以下内容:

<meta name="description" content="The Break-ezee is a vital piece of equipment for anyone when breaking horses - As used by Mary King.

The Break-ezee is an all in one progressi" />

无论如何我可以替换任何标签(在本例中为

)以便没有空格吗?

理想情况下,我希望元描述看起来像这样:

<meta name="description" content="The Break-ezee is a vital piece of equipment for anyone when breaking horses - As used by Mary King. The Break-ezee is an all in one progressi" />

此外,我认为 Google 不会为元描述选择额外的空间是否正确?

非常感谢您的帮助。

最佳答案

你可以使用 str_replace

$showseodesc = str_replace(array('<p>', '</p>'), '', $showseodesc);

$showseodec = substr($showseoproduct['text'],0, 160);

关于php - 在 PHP 中用空格替换标签以实现 SEO 元描述,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17063032/

相关文章:

PHPExcel 创建电子表格的时间过长

php - 如何同时执行多个MySql查询?

mysql - 使用预定义的 root 密码安装脚本 LAMP

MYSQL 优化与混合和/或

PHP:替换字符串中所有出现的 "[CODE]...[/CODE]"

javascript - 将 td 值传递给 JavaScript

php - YouTube channel 供稿

javascript - 如何将js鼠标坐标获取到php插入查询中?

java - 正则表达式 java : how to replace a string in a generic between the start tag and end tag of a generic

javascript - 如何获取 span 的 id 并使其不显示动态生成的内容?