将html标签替换为class和var php


Replace html tag with class and var php

我想替换我从数据库中获得的字符串。我想用一个空字符串替换span

我的字符串是这样的:

<p><span class="coursehours">x horas lectivas</span>
<span class="coursehours">x horas prácticas</span></p>

X是一个数字,我想删除整个p标签。

我该怎么办?

我认为这应该工作了吗?

var text = "<p> <span class='coursehours'>x horas lectivas</span> <span class='coursehours'>x horas prácticas</span></p>";
var str = text.trim().substring(3, text.length - 4);
alert(str.trim());

对不起,我解释错了

我想要消除的只是那些span

似乎这是固定的

preg_replace('#<span class="coursehours">(.*?)</span>#', '', $string);

感谢大家!

尝试从字符串中剥离HTML和PHP标记

http://php.net/manual/en/function.strip-tags.php

像这样:

$str = "your string";
$str = strip_tags($str);