Page 1 of 1
Regular Expression
Posted: Mon Oct 24, 2005 4:58 am
by vineet
Hi,
Can any body help me. I am new in php.I want to trape all rows containing <td> or <td height="15" etc... td attribute >.
$chars = preg_split('/<td *>/i', $mystring);
print_r($chars);
I am using this code but it is not extracting any thing..
How i can do this.
Please Help...
Posted: Mon Oct 24, 2005 6:11 am
by Jenk
Maybe something like:
Code: Select all
$chars = preg_split("/<td[^<>]*>/", $mystring);
There is also a RegEx sub-forum on this site

Posted: Mon Oct 24, 2005 10:46 am
by foobar
Posted: Tue Oct 25, 2005 12:12 am
by vineet
Thanx Jank,
But it is not working. I use this
Code: Select all
$chars = preg_split('/<td.*>/i',$mystring);
It is working but problem is that it is now not trapping <td> and trapping all td's with attributes like this<td height="16" etc...>. I think problem is of "." it is saying that one character after <td. Can any body tell any symbol that we can use to denote 0 or more character like "." is denoting one character.
Vineet.
Posted: Tue Oct 25, 2005 8:39 am
by feyd
preg_split, by default will not keep the breaking points, similar to explode. You can tell it, PREG_SPLIT_DELIM_CAPTURE for it's flags argument..
At any rate, your pattern has the possibility to capture far more than just a TD tag. It's better to use Jenk's example.