Page 1 of 1

regular expression to get contents from HTML tags

Posted: Sun May 20, 2007 7:41 am
by amir
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.

Posted: Sun May 20, 2007 7:42 am
by feyd
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?

Posted: Sun May 20, 2007 7:44 am
by amir
actually I dont know how to get these values and I want to know how can I do this with or without regular expression?

Posted: Sun May 20, 2007 8:04 am
by feyd
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.

Posted: Sun May 20, 2007 8:30 am
by amir
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 =)