0

I have the following code in 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;
}

I need a function that will extract the body content. All the examples that I saw here were kinda fixed on a particular example , and i need it on dynamic basis. This function can do it for me, I just need it in php.

Marco Bonelli
  • 63,369
  • 21
  • 118
  • 128

2 Answers2

0

This should be really easy to transcode to PHP. Look for preg_match and preg_replace in the PHP Manual.

Florian Grell
  • 995
  • 7
  • 18
-1

Try strip_tags.

$html = "<body><a href='http://example.com'>Something</a> <b>big</b> is coming</body>";
echo strip_tags($html); // Something big is coming
samlev
  • 5,852
  • 1
  • 26
  • 38