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)){
                        list($r,$iulast)=explode($csn,$iugl);
                        if ($csen!=”){
                                list($iulast,$r)=explode($csen,$iulast);      
                        }
                        return trim($iulast);
                }else {return “XX”;}
        }else{
                if ($csen!=”){
                        list($iulast)=explode($csen,$iugl);
                        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 comment

Create a free website or blog at WordPress.com.