Regular Expression

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
vineet
Forum Newbie
Posts: 2
Joined: Mon Oct 24, 2005 4:55 am

Regular Expression

Post 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...
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

Maybe something like:

Code: Select all

$chars = preg_split("/<td[^<>]*>/", $mystring);
There is also a RegEx sub-forum on this site :)
foobar
Forum Regular
Posts: 613
Joined: Wed Sep 28, 2005 10:08 am

Post by foobar »

php.net is your friend.
vineet
Forum Newbie
Posts: 2
Joined: Mon Oct 24, 2005 4:55 am

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
Post Reply