php中的翻译javascript函数

php中的翻译javascript函数,javascript,php,html,Javascript,Php,Html,我在jS中有以下代码: function stripHTMLWithLinks(c) { var BodyContents = /([\s\S]*\<body[^\>]*\>)([\s\S]*)(\<\/body\>[\s\S]*)/i ; var h = c.match(BodyContents); if (h != null && h[2]) { c = h[2]; } c = c.repla

我在jS中有以下代码:

function stripHTMLWithLinks(c) {
    var BodyContents = /([\s\S]*\<body[^\>]*\>)([\s\S]*)(\<\/body\>[\s\S]*)/i ;
    var h = c.match(BodyContents);

  if (h != null && h[2]) {
        c = h[2]; 
  }

    c = c.replace(/<a\s.*?href\s*=\s*"(.*?)".*?>(.*?)<\/a>/gi, "$2 [$1]");
    c = c.replace(/<a\s.*?href\s*=\s*'(.*?)'.*?>(.*?)<\/a>/gi, "$2 [$1]");
    c = c.replace(/\/\/--\>/gi, "");
    c = c.replace(/(\n)/gi,"");
    c = c.replace(/(\r)/gi,"");
    c = c.replace(/<title[^\>]*\>[\s\S]*\<\/title\>/gi,"");
    c = c.replace(/<br\s*\/\s*>/gi,"\n");
    c = c.replace(/(<\/h.>|<\/p>|<\/div>)/gi, "$1\n\n");
    c = c.replace(/<[^>]+>/g,"");
    c = c.replace(/&lt;/g,"<");
    c = c.replace(/&gt;/g,">");
    c = c.replace(/&nbsp;/g," ");
    return c;
}
函数条HTMLWITHLINKS(c){
var BodyContents=/([\s\s]*\]*\>)([\s\s]*)(\[\s\s]*)/i;
var h=c.匹配(主体内容物);
如果(h!=null&&h[2]){
c=h[2];
}
c=c.替换(/(.*)/gi,“$2[$1]”);
c=c.替换(/(.*)/gi,“$2[$1]”);
c=c.替换(/\/-\>/gi,”);
c=c.替换(/(\n)/gi,“”);
c=c.替换(/(\r)/gi,“”);
c=c.replace(/]*\>[\s\s]*\/gi,”);
c=c.replace(//gi,“\n”);
c=c.replace(/(| |)/gi,“$1\n\n”);
c=c.替换(/]+>/g,“”);
c=c.replace(//g,“”);
c=c.replace(//g,“”);
返回c;
}
我需要一个函数来提取正文内容。我在这里看到的所有例子都是固定在一个特定的例子上的,我需要它是动态的。这个函数可以帮我完成,我只需要在php中使用它。

试试

$html=“大人物来了”;
echo strip_标记($html);//有大事要发生了

这应该很容易转换到PHP。
在PHP手册中查找和。

True,但OP要求翻译为PHP。
$html = "<body><a href='http://example.com'>Something</a> <b>big</b> is coming</body>";
echo strip_tags($html); // Something big is coming