Jump to content

preg_match_all for html tags


sonal4php

Recommended Posts

i want to retrieve certain elements bound in same format in an html file.

i have lot much raw data in this html file,

i have stored this in string =$data

 

and i am looking for such pattern:

<td width='15%' valign=top>41    </td>

among which 41 is desired result.

 

note: 15% is not constant it can be 15%,25% and 35%

 

i have many rows like this in html file, and i want to pick the same value which is bound in

<td width='15%' valign=top>

and

</td>

i am trying this code:

 

preg_match_all("|<[td width='[0-9]{1}5%' valign=top>]+>(.*)</[/td>]+>|U",$data,$out,PREG_PATTERN_ORDER);
print_r($out[1]);

but i am not getting desired result

can someone please help....

 

thanx

Link to comment
Share on other sites

[...] is a character class which does not match a sequence of characters, but individual characters.

 

<pre>
<?php
$string = "<td width='15%' valign=top>41    </td>";
preg_match_all("/<td width='\d+%' valign=top>(\d+)/", $string, $out);
print_r($out[1][0]);
?>
</pre>

Link to comment
Share on other sites

hi,

i am trying a lil different code in regex on the same logic

 

$string="get data(s):</td><td><em>MY DATA</em>";
preg_match_all("/get data(s):</td><td><em>(.*)</em>/", $string, $out);
print_r($out);

 

i want to pick "MY DATA"

but this isn't permits /td and /em in pattern..

what's the solution..

 

and can u please suggest some easy to learn regex tutorial...

thanx

 

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.