在PHP中将标记替换为空格,用于SEO元描述
我正在尝试将mySQL数据库中的HTML标记剥离为纯文本,以用于SEO元描述。数据库中的HTML如下所示:在PHP中将标记替换为空格,用于SEO元描述,php,mysql,tags,seo,meta-tags,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 tra
<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>
<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" />
我是否可以替换任何标记(在本例中为),这样就没有空格了
理想情况下,我希望元描述如下所示:
<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>
<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" />
另外,我认为谷歌没有为元描述增加额外的空间,对吗
非常感谢您的帮助。您可以使用
str\u replace
$showseodesc=str_replace(数组(“”、“”)、“$showseodesc”)代码>
$showseodec=substr($showseoproduct['text'],01160)代码>试试这个,使用正则表达式
$string = "<p>The Break-ezee is a vital piece of equipment for anyone when breaking horses - As used by Mary King.</p>";
print preg_replace("|<[^>]+>|si","",$string); // <-- strip all tags from a string.
print preg_replace("|<p[^>]*>|si","",$string); // <-- strip all <p...> tags from a string.
$string=“断马钳是任何人在断马时的重要装备,玛丽·金就是这么用的。”;
打印preg_replace(“|]+>| si”,“”,$string);// 试试这个:
$showseodesc = trim(
preg_replace("/\n+/"," " ,
strip_tags(
substr($showseoproduct['text'], 0, 160)
)
)
);
注意preg\u replace
,它将每个换行符更改为一个空格。str\u replace就足够了:-
$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>";
echo str_replace(array('<p>', '</p>'), '', $html);
$html=“Break ezee是任何人在驯马时的重要装备,玛丽·金(Mary King)就是这么用的
Break ezee是一款集多功能于一体的渐进式训练产品,可在断马时使用。“;
echo str_替换(数组(“”,“”),“$html);
输出:-
断马钳是任何人断马时的重要装备,玛丽·金就是这么用的。Break ezee是一款集所有功能于一体的渐进式训练产品,用于驯马