Rohit Aggarwal

February 5, 2009

PHP Functions for parsing data

Filed under: Interesting,Web Applications (IS 4460) — Rohit Aggarwal @ 3:24 am

function html2text($document){
        $search = array(‘@<script[^>]*?>.*?</script>@si’,  // Strip out javascript
                                   ‘@<[\/\!]*?[^<>]*?>@si’,            // Strip out HTML tags
                                   ‘@<style[^>]*?>.*?</style>@siU’,    // Strip style tags properly
                                   ‘@<![\s\S]*?–[ \t\n\r]*>@’        // Strip multi-line comments including CDATA
        $text = preg_replace($search, ”, $document);
        return $text;

function getrequired($iugl,$csn,$csen){
        if ($csn!=”){
                if (preg_match(“/$csn/”,$iugl)){
                        if ($csen!=”){
                        return trim($iulast);
                }else {return “XX”;}
                if ($csen!=”){
                        return trim($iulast);
                }else {return “XX”;}


1 Comment »

  1. Rohit,

    Thanks for a very succinct script. Sometimes this type of information is not presented in a way that can be easily applied in real life. This is good stuff! I’ve now got two extra defenses against spam/attacks.

    Thank You,
    Tony Fantis

    Comment by Tony Fantis — January 14, 2011 @ 11:54 pm | Reply

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

Blog at

%d bloggers like this: