I am kinda beginner in regular expressions.
Could anyone help me out? I wanna get as an output “Stephen” word.
<td width=20%>Name:</td><td>Stephen <div style="float: right"></div></td>
I am kinda beginner in regular expressions.
Could anyone help me out? I wanna get as an output “Stephen” word.
<td width=20%>Name:</td><td>Stephen <div style="float: right"></div></td>
preg_match("#<td width=20%>Name:</td><td>([\\w^<]+)#", $search_string, $matches);
Didn’t test it, might not work.
Unfortunately , does not work.
$str = '<td width=20%>Name:</td><td>Stephen <div style="float: right"></div></td>';
preg_match("#<td width=20%>Name:</td><td>([\\w^<]+)#", $str, $matches);
var_dump($matches);
Works perfectly fine for me.
You’re right.
For this spare of code it works.
But im fetching first:
preg_match(
"@<TABLE BORDER=0 CELLSPACING=1 CELLPADDING=4 WIDTH=100%>
<TR BGCOLOR=#505050><TD COLSPAN=2 CLASS=white>
<B>Informations</B>.+?</TABLE>@is", $website, $matches );
$getinfo = $matches[0];
$website is a variable of the site I am connecting to.
Then I am trying to fetch the data included in this table.
preg_match("@<td width=20%>Name:</td><td>([\\w^<]+)@", $getinfo, $matches);
Maybe 1st preg_match should be fixed?
Your regular expression (the 1st one) won’t capture anything in the $matches variable since you’re not using any () to actually put the contents of the matched string inside a variable.
Also, you need $matches[1], not $matches[0].
How it should be fixed then?
If you are parsing complex HTML, take a long, hard look at Simple HTML DOM instead of writing regular expressions:
http://simplehtmldom.sourceforge.net/
Tables without classes do present a problem for selectors but is still a lot easier to navigate than parsing HTML yourself.
Seems very useful , need only explore some functions I need.