我正在尝试将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/