Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP using preg 1

Status
Not open for further replies.

soundmind

Technical User
Jun 30, 2003
16
US
Hi,

I'm writing a php app that strips out only text from a .html page so I can insert them into a database and work from there.

To begin, I'm attemping to get all the text in between <td>s but haven't worked out quite well yet. (I'll move onto the <img>s and <a>s inside the <td>s after I successfully retrieve the contents.)

<?
$file = fopen(&quot;testpage.html&quot;, r);
fpassthru($file);

while (!feof($file))
{
preg_match_all(&quot;/^\<td(\>\=\&quot;\.){0,}<\/td>$/&quot;, $textString, $matches);
}
?>

My preg knowledge is less than perfect, could you help me? Thanks!


 
Your invokation of fpassthru() is going to keep any code from running. states that fpassthru() streams a file to the output buffer and then closes the file handle. Your while statement will never run.

What, exactly, are you trying to grab in your regular expression? Given the following string:

<td class=&quot;myclass&quot; width=&quot;3&quot;>foo</td>

Your expression will grab:

class=&quot;myclass&quot; width=&quot;3&quot;>foo

Is that what you want? Or just what's between the <td ....>...</td> tags?

Want the best answers? Ask the best questions: TANSTAAFL!!
 
I'm trying to grab only what's in between the <td....>foo</td> tags. Just &quot;foo&quot; in this case. I guess I need a way to say &quot;ignore&quot; the properties inside the <td...> tag.

Hope I'm clear this time.
 
Then don't include them in your parenthesized sub-expression.

A regex like:

'/<td[^>]*>([^<]*)<\/td>/'

Should get you close.

Keep in mind that newlines, tabs, etc., will also be matched inside the <td>...</td> tags.

Want the best answers? Ask the best questions: TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top