【发布时间】:2020-01-01 21:02:39
【问题描述】:
我有一个名为“5 Fragen an ... xyz”的字符串(wordpress 标题) 在我删除 HTML 标记后,该标题中的点应该是 删除/更换。我除了字符串只显示'xyz'
<?php
$wptitle = get_the_title($post->id); // getwordpress title
$wptitle = strip_tags($wptitle); // remove a <br> tag
$wptitle = preg_replace('/\.(?=.*\.)/', ' ', $wptitle); // want to remove the dots
$wptitle = str_replace('5 Fragen an', '', $wptitle); // remove the part 5 Fragen an
echo $wptitle
?>
【问题讨论】:
-
总是三个点吗?如果是这样 - 使用
explode()的东西可以做到。 -
字符串显示“xyz”,因为您使用
str_replace删除了它的其余部分。如果要删除三个点,只需在三个点上执行 str_replace 即可。 -
如果总是三个点。 $output = str_replace('...','','mystring...');