PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
amir
Forum Contributor
Posts: 287 Joined: Sat Oct 07, 2006 4:28 pm
Post
by amir » Sun May 20, 2007 7:41 am
Hello,
How can I get contents from HTML tags?
Code: Select all
<table width="40%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="left" class="css_text">Name</td>
<td>Aamir</td>
</tr>
<tr>
<td align="left" class="css_email">Email</td>
<td>abc@mail.com</td>
</tr>
<tr>
<td align="left" class="css_phone">Phone</td>
<td>1234567890</td>
</tr>
</table>
I would like to get it as
Code: Select all
$name = 'Aamir';
$email = 'abc@mail.com';
$phone = '1234567890';
Thanks in Advance.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sun May 20, 2007 7:42 am
It will take a bit more than simply a regular expression to generate individual variables.
What have you tried as far as the regular expression goes?
amir
Forum Contributor
Posts: 287 Joined: Sat Oct 07, 2006 4:28 pm
Post
by amir » Sun May 20, 2007 7:44 am
actually I dont know how to get these values and I want to know how can I do this with or without regular expression?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sun May 20, 2007 8:04 am
There have been many threads on extracting data from within HTML tags. If you're unwilling to attempt an expression, I can't help you.
amir
Forum Contributor
Posts: 287 Joined: Sat Oct 07, 2006 4:28 pm
Post
by amir » Sun May 20, 2007 8:30 am
I am sorry to hurt you but here is what I wanted
Code: Select all
preg_match_all("|<[^>]+>(.*)</[^>]+>|U",
"<td align=\"left\" class=\"css_text\">Name</td><td>Aamir</td>
<td align=\"left\" class=\"css_email\">Email</td><td>abc@mail.com</td>
<td align=\"left\" class=\"css_phone\">Phone</td><td>1234567890</td>",
$out, PREG_SET_ORDER);
echo $out[0][0].' = '.$out[1][0]."<br>";
echo $out[2][0].' = '.$out[3][0]."<br>";
echo $out[4][0].' = '.$out[5][0]."<br>";
Thanks for your support =)