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
https://forums.phpfreaks.com/topic/37627-preg_match_all-for-html-tags/
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>

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

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.