#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2009
    Posts
    1
    Rep Power
    0

    Cool Preg_match on HTML Characters


    Hey guys,

    I'm a newbie to regex and have looked up a ton of tutorials and eventually came across this forum where it looks like I may get some help.

    I'm pulling in an XML feed that has HTML characters in between the xml tags. I believe it's encoding the HTML characters.

    For Example:
    Code:
    '<div>' is coming out as '& lt;div& gt;'
    I want the content that is between these div tags.

    Code:
    For Example using: & lt;div& gt;This is my text!& lt;/div& gt;
    I want simply, "This is my text!"
    I'm trying:
    Code:
    preg_match("/& lt;div& gt;(.*)& lt;/div& gt;/", $string, $matches);
    ...but this does not seem to be working!

    Anyone know whats wrong or how to format the reg expression for this scenario?!

    Thanks so much in advance!
  2. #2
  3. No Profile Picture
    User 165270
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2005
    Posts
    497
    Rep Power
    938
    I recommend parsing that XML with an XML parser and then using PHP's built-in functions to encode/decode the html:
    http://us3.php.net/htmlentities

IMN logo majestic logo threadwatch logo seochat tools logo