Jump to content

Help parsing HTML


Airhead315

Recommended Posts

Im having probably the most rediculous problems with the simplest regular expression ever. Here is the code im trying to parse out of:

<B>Original Message:</B>
<P>
<b>Posted by:</b> someguys name
  (<a href="mailto:someguy@somesite.com
">someguy@somesite.com
</a>)<BR>
<b>Organization:</b><a href="http://www.somesite.com
">JAQUET Ltd
</a> <BR><b>Date posted:</b> Thu Jan 14  5:23:11 US/Eastern 2001
<br>
<b>Subject:</b> some subject of a forum
<br>
<b>Message:</b><br> some long message that has no html tags in it
no breaks and no other weird charachters

 

I tried getting just one part of the meta data I wanted with the following code

preg_match("/<b>Posted by:<\/b>(.*)<BR>/i", $parts[$i],$innerparts);
echo $innerparts[1];

 

As you can see im trying to get the Name/Email of the user who posted the message. However im not getting anything back("Undefined offset: 1")

 

$parts[$i] holds the content shown above.

 

I also tried the following lines with the same result

preg_match("/\<b\>Posted by:\<\/b\>(.*)\<BR\>/i", $parts[$i],$innerparts);

preg_match("/<b>Posted by:<\/b>(.*?)<BR>/i", $parts[$i],$innerparts);

preg_match("/<b>Posted by:<\/b>(.*?)<BR>/i", $parts[$i],$innerparts);

Link to comment
Share on other sites

I would use this:

 

preg_match("/<b>Posted by:<\/b>(.*?)<BR>/is", $parts[$i],$innerparts);

 

It looks like you've got newlines in your input, and the dot metacharacter won't match newlines unless you give it permission in the form of the /s modifier.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.