Python regex ignore new line - php

I have web page look like this
<td valign="top">
<table width="100%" border="0" cellspacing="2" cellpadding="1" class="main_tb3">
<tr>
<td colspan="2">
<div align="center">
<a href="/title/name.php" target="_blank">
<img src="./movie/image.jpg" alt="TitleName" border="0" height="100" width="225" />
</a>
</div>
</td>
</tr>
<tr>
<td colspan="2"><h1 align="center">Title - secondname</h1></td>
</tr>
<tr>
<td><span class="style10">Cat1 :</span></td>
<td>1st name</td>
</tr>
<tr>
<td width="32%"><span class="style10">Cat2 :</span></td>
<td width="68%"><b><i>secondname</i></b></td>
</tr>
<tr>
<td><span class="style10">cat4 :</span></td>
<td>Bla bla</td>
</tr>
<tr>
<td><span class="style10">Cat3 :</span></td>
<td>thirdName2</td>
</tr>
</table>
</td>
<td valign="top">
<table width="100%" border="0" cellspacing="2" cellpadding="1" class="main_tb3">
<tr>
<td colspan="2">
<div align="center">
<a href="/title/name.php" target="_blank">
<img src="./movie/image.jpg" alt="TitleName" border="0" height="100" width="225" />
</a>
</div>
</td>
</tr>
<tr>
<td colspan="2"><h1 align="center">Title - secondname</h1></td>
</tr>
<tr>
<td><span class="style10">Cat1 :</span></td>
<td>1st name</td>
</tr>
<tr>
<td width="32%"><span class="style10">Cat2 :</span></td>
<td width="68%"><b><i>secondname</i></b></td>
</tr>
<tr>
<td><span class="style10">cat4 :</span></td>
<td>Bla bla</td>
</tr>
<tr>
<td><span class="style10">Cat3 :</span></td>
<td>thirdName2</td>
</tr>
</table>
</td>
I would like to get certain values from this site using python regex.
After <div align="center"> I like to get href value: "/title/name.php" and img src: "./movie/image.jpg" and Title - secondname from <h1 align="center">Title - secondname</h1>
i have tried this:
regex = 'class="main_tb3"*\n<a href="(.+?)" target="_blank">\n<img src="(.+?)"'
please help me

you can use below regex
For href value: <a href="(.*?)"
For Image src: <img src="(.*?)"
For Title: titleid=12">(.*?)<

You will find it a lot simpler to install something like BeautifulSoup to do this:
from bs4 import BeautifulSoup
html = """
<td valign="top">
<table width="100%" border="0" cellspacing="2" cellpadding="1" class="main_tb3">
<tr>
<td colspan="2">
<div align="center">
<a href="/title/name.php" target="_blank">
<img src="./movie/image.jpg" alt="TitleName" border="0" height="100" width="225" />
</a>
</div>
</td>
</tr>
<tr>
<td colspan="2"><h1 align="center">Title - secondname</h1></td>
</tr>
<tr>
<td><span class="style10">Cat1 :</span></td>
<td>1st name</td>
</tr>
<tr>
<td width="32%"><span class="style10">Cat2 :</span></td>
<td width="68%"><b><i>secondname</i></b></td>
</tr>
<tr>
<td><span class="style10">cat4 :</span></td>
<td>Bla bla</td>
</tr>
<tr>
<td><span class="style10">Cat3 :</span></td>
<td>thirdName2</td>
</tr>
</table>
</td>
<td valign="top">
<table width="100%" border="0" cellspacing="2" cellpadding="1" class="main_tb3">
<tr>
<td colspan="2">
<div align="center">
<a href="/title/name.php" target="_blank">
<img src="./movie/image.jpg" alt="TitleName" border="0" height="100" width="225" />
</a>
</div>
</td>
</tr>
<tr>
<td colspan="2"><h1 align="center">Title - secondname</h1></td>
</tr>
<tr>
<td><span class="style10">Cat1 :</span></td>
<td>1st name</td>
</tr>
<tr>
<td width="32%"><span class="style10">Cat2 :</span></td>
<td width="68%"><b><i>secondname</i></b></td>
</tr>
<tr>
<td><span class="style10">cat4 :</span></td>
<td>Bla bla</td>
</tr>
<tr>
<td><span class="style10">Cat3 :</span></td>
<td>thirdName2</td>
</tr>
</table>
</td>"""
soup = BeautifulSoup(html)
for table in soup.find_all("table", class_="main_tb3"):
print table.find('a').get('href')
print table.find('h1').text
For the HTML you have given, this will print the following:
/title/name.php
Title - secondname
/title/name.php
Title - secondname

Related

How to do make html foreach table?

I tried to do it but the big problem is foreach here i have the foto:
Problem
Here is my table picture
Here is the code but still have problem:
<div class="row">
<table class="table table-bordered table-striped table-highlight">
<tbody>
<tr height="100">
<td rowspan="6" height="120" width="3%" style="vertical-align: middle;">
<p style="white-space: nowrap;writing-mode: vertical-lr;transform: rotate(180deg);font-weight: bold;"><font >Here is my title </font></p>
</td>
<td colspan="3">
<font>Name</font>
</td>
<td width="64">
<font>Article</font>
</td>
<td width="64">
<font>Price</font>
</td>
<td width="64">
<font>Date</font>
</td>
</tr>
<tr height="20">
<td colspan="3" rowspan="5" height="120" ></td>
<td rowspan="5" style="vertical-align: top;"></td>
<td rowspan="5" style="vertical-align: top;"></td>
<td rowspan="5" style="vertical-align: top;"></td>
</tr>
<tr height="15">
</tr>
<tr height="15">
</tr>
<tr height="15">
</tr>
<tr height="15">
</tr>
</tbody>
</table>
</div>
How can i do it so that when i use foreach it will insert new td and the vertical Here is my title will be there?
ok, so you're using php here's a very basic example on how you can do that, i'm assuming you already did query and the fetching part, and this is a guess of your data structure, you can adjust it to your liking :
<div class="row">
<table class="table table-bordered table-striped table-highlight">
<tbody>
<tr height="100">
<td rowspan="100%" height="120" width="3%" style="vertical-align: middle;">
<p style="white-space: nowrap;writing-mode: vertical-lr;transform: rotate(180deg);font-weight: bold;"><font >Here is my title </font></p>
</td>
<td colspan="3">
<font>Name</font>
</td>
<td width="64">
<font>Article</font>
</td>
<td width="64">
<font>Price</font>
</td>
<td width="64">
<font>Date</font>
</td>
</tr>
<?php
foreach($data as $key => $value){
echo '<tr height="20">';
echo '<td colspan="3">'.$value['name'].'</td>';
echo '<td width="64" style="vertical-align: top;">'.$value['article'].'</td>';
echo '<td width="64" style="vertical-align: top;">'.$value['price'].'</td>';
echo '<td width="64" style="vertical-align: top;">'.$value['date'].'</td>';
echo '</tr>';
}
?>
</tbody>
</table>
</div>
here's a fiddle : https://jsfiddle.net/kkpjx328/
I hope this helps .
PS : on your next question, please consider adding the data structure and if possible, an example or code sample of what you've tried so far so we can provide more specific answers

set variable to element from other site (PHP)

I'm not the best at explaining things but here I go,
On a different site, I have 10 elements that i want to get and assign to variables
this is how they are
element 1:
<div class="username_header dynamic_fontsize" style="font-size: 48px; top: 0px;">
<span class="username">[element 1]</span>
<span class="user_online_msg">stuff</span>
</div>
elements 2-10
<div class="forum_profile_right_block">
<table border="0" width="97%" cellspacing="2" cellpadding="5">
<tbody>
<tr>
<td>
<div style="font-color:black; font-size:1em">abc2</div>
</td>
<td colspan="2" align="center" bgcolor="#F0F0F0">[element 2]</td>
</tr>
<tr>
<td>
<div style="font-color:black; font-size:1em">abc34</div>
</td>
<td align="center" bgcolor="#F0F0F0">[element 3]</td>
<td align="center" bgcolor="#F0F0F0">[element 4]</td>
</tr>
<tr>
<td>
<div style="font-color:black; font-size:1em">abc5</div>
</td>
<td colspan="2" align="center" bgcolor="#F0F0F0">[element 5]</td>
</tr>
<tr>
<td>
<div style="font-color:black; font-size:1em">abc6</div>
</td>
<td colspan="2" align="center" bgcolor="#F0F0F0">[element 6]
</td>
</tr>
<tr>
<td>
<div style="font-color:black; font-size:1em">abc7</div>
</td>
<td colspan="2" align="center" bgcolor="#F0F0F0">[element 7]</td>
</tr>
<tr>
<td>
<div style="font-color:black; font-size:1em">abc8</div>
</td>
<td colspan="2" align="center" bgcolor="#F0F0F0">[element 8]</td>
</tr>
<tr>
<td>
<div style="font-color:black; font-size:1em">abc9</div>
</td>
<td colspan="2" align="center" bgcolor="#F0F0F0">
<div style="display:inline-block;">[element 9]</div>
<div style="display: inline-block; position: relative; top: 1px;"><img src="images/msdropdown/icons/blank.gif" class="flag us"></div>
</td>
</tr>
<tr>
<td>
<div style="font-color:black; font-size:1em">abc10</div>
</td>
<td colspan="2" align="center" bgcolor="#F0F0F0">[element 10]
</td>
</tr>
</tbody>
</table>
<br>
</div>

PHP Submit button not responding (Codeigniter)

I have the following view (home_view.php)
<?php $this->load->helper('url');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>diluks eCommerce - Home</title>
<link href="<?php echo base_url();?>Public/scripts/style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<form action="<?php echo base_url();?>index.php/welcome_controller" method="post">
<div class="container">
<?php
$userpermission = $this->session->userdata('userpermission');
if($userpermission==1){
include 'header-admin.php';
}
else if($userpermission==2){
include 'header-user.php';
}
else{
include 'header-guest.php';}
?>
<div class="level3 clearfix">
<?php include 'shopping-sidebar.php'; ?>
<div class="body-content">
<div class="image-slider">
<img src="<?php echo base_url();?>Public/img/main-img.png" width="785" height="220" />
</div>
<div class="seperate-space">
<div class="separate-title"><a class="bold-captions">Latest Picks</a>
</div>
</div>
<div class="items">
<div class="item-holder">
<table align="center" width="256px" cellpadding="0px" cellspacing="0px">
<tr>
<td class="item-info" align="center" height="34px">Item name</td>
</tr>
<tr>
<td class="item-info" align="center" height="230px">
<img src="<?php echo base_url();?>Public/img/sunflowers.png" width="256" height="230" />
</td>
</tr>
<tr>
<td class="item-info" align="center" height="34px">$30</td>
</tr>
<tr>
<td class="item-info" align="center" height="35px"><input name="btn_read" class="readbtn" value="Read More" /></td>
</tr>
</table>
</div>
<div class="item-holder">
<table align="center" width="256px" cellpadding="0px" cellspacing="0px">
<tr>
<td class="item-info" align="center" height="34px">Item name</td>
</tr>
<tr>
<td class="item-info" align="center" height="230px">
<img src="<?php echo base_url();?>Public/img/treecard.png" width="256" height="230" />
</td>
</tr>
<tr>
<td class="item-info" align="center" height="34px">$30</td>
</tr>
<tr>
<td class="item-info" align="center" height="35px"><input name="btn_read" class="readbtn" value="Read More" /></td>
</tr>
</table>
</div>
<div class="item-holder">
<table align="center" width="256px" cellpadding="0px" cellspacing="0px">
<tr>
<td class="item-info" align="center" height="34px">Item name</td>
</tr>
<tr>
<td class="item-info" align="center" height="230px">
<img src="<?php echo base_url();?>Public/img/3-flowers.png" width="256" height="230" />
</td>
</tr>
<tr>
<td class="item-info" align="center" height="34px">$30</td>
</tr>
<tr>
<td class="item-info" align="center" height="35px"><input name="btn_read" class="readbtn" value="Read More" /></td>
</tr>
</table>
</div>
<div class="item-holder">
<table align="center" width="256px" cellpadding="0px" cellspacing="0px">
<tr>
<td class="item-info" align="center" height="34px">Item name</td>
</tr>
<tr>
<td class="item-info" align="center" height="230px">
<img src="<?php echo base_url();?>Public/img/sunflowers.png" width="256" height="230" />
</td>
</tr>
<tr>
<td class="item-info" align="center" height="34px">$30</td>
</tr>
<tr>
<td class="item-info" align="center" height="35px"><input name="btn_read" class="readbtn" value="Read More" /></td>
</tr>
</table>
</div>
<div class="item-holder">
<table align="center" width="256px" cellpadding="0px" cellspacing="0px">
<tr>
<td class="item-info" align="center" height="34px">Item name</td>
</tr>
<tr>
<td class="item-info" align="center" height="230px">
<img src="<?php echo base_url();?>Public/img/treecard.png" width="256" height="230" />
</td>
</tr>
<tr>
<td class="item-info" align="center" height="34px">$30</td>
</tr>
<tr>
<td class="item-info" align="center" height="35px"><input name="btn_read" class="readbtn" value="Read More" /></td>
</tr>
</table>
</div>
<div class="item-holder">
<table align="center" width="256px" cellpadding="0px" cellspacing="0px">
<tr>
<td class="item-info" align="center" height="34px">Item name</td>
</tr>
<tr>
<td class="item-info" align="center" height="230px">
<img src="<?php echo base_url();?>Public/img/3-flowers.png" width="256" height="230" />
</td>
</tr>
<tr>
<td class="item-info" align="center" height="34px">$30</td>
</tr>
<tr>
<td class="item-info" align="center" height="35px"><input name="btn_read" class="readbtn" value="Read More" /></td>
</tr>
</table>
</div>
<div class="item-holder">
<table align="center" width="256px" cellpadding="0px" cellspacing="0px">
<tr>
<td class="item-info" align="center" height="34px">Item name</td>
</tr>
<tr>
<td class="item-info" align="center" height="230px">
<img src="<?php echo base_url();?>Public/img/sunflowers.png" width="256" height="230" />
</td>
</tr>
<tr>
<td class="item-info" align="center" height="34px">$30</td>
</tr>
<tr>
<td class="item-info" align="center" height="35px"><input name="btn_read" class="readbtn" value="Read More" /></td>
</tr>
</table>
</div>
<div class="item-holder">
<table align="center" width="256px" cellpadding="0px" cellspacing="0px">
<tr>
<td class="item-info" align="center" height="34px">Item name</td>
</tr>
<tr>
<td class="item-info" align="center" height="230px">
<img src="<?php echo base_url();?>Public/img/treecard.png" width="256" height="230" />
</td>
</tr>
<tr>
<td class="item-info" align="center" height="34px">$30</td>
</tr>
<tr>
<td class="item-info" align="center" height="35px"><input name="btn_read" class="readbtn" value="Read More" /></td>
</tr>
</table>
</div>
<div class="item-holder">
<table align="center" width="256px" cellpadding="0px" cellspacing="0px">
<tr>
<td class="item-info" align="center" height="34px">Item name</td>
</tr>
<tr>
<td class="item-info" align="center" height="230px">
<img src="<?php echo base_url();?>Public/img/3-flowers.png" width="256" height="230" />
</td>
</tr>
<tr>
<td class="item-info" align="center" height="34px">$30</td>
</tr>
<tr>
<td class="item-info" align="center" height="35px"><input name="btn_read" class="readbtn" value="Read More" /></td>
</tr>
</table>
</div>
</div>
</div>
</div>
<div style="clear:both"></div>
<div class="level4">
<div class="footer-area">
<div class="lined-space"></div>
<div class="site-map" align="left">
<table>
<tr>
<td class="footer-text">About Us</td>
<td class="footer-text">Facebook</td>
</tr>
<tr>
<td class="footer-text">Contact Us</td>
<td class="footer-text">Twitter</td>
</tr>
<tr>
<td class="footer-text">FAQs</td>
<td class="footer-text">Terms & Conditions</td>
</tr>
<tr>
<td class="footer-text">Help</td>
</tr>
</table>
</div>
<div class="developer-info">
<a class="developers-text">Designed & Developed By Diluks Software Solutions.</a>
</div>
</div>
</div>
</div>
</form>
</body>
</html>
And the controller for that (welcome_controller) is the following,
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Welcome_controller extends CI_Controller {
function __construct(){
parent::__construct();
}
public function index()
{
if(isset($_POST["btn_login"])){
$data = array();
$this->load->model('category_model');
$data['categories'] = $this->category_model->getCategories();
$this->load->view('login_view', $data);
}
else if(isset($_POST["btn_adminpanel"])){
$this->load->view('adminpanel_view');
}
else if(isset($_POST["btn_logout"])){
$this->session->sess_destroy();
$data = array();
$this->load->model('category_model');
$data['categories'] = $this->category_model->getCategories();
$this->load->view('home_view', $data);
}
else if(isset($_POST["btn_read"])){
$this->load->view('readmore_view');
}
}
}
Now I need to redirect the page to readmore_view onClick of the button named 'btn_read', But it doesn't respond. (Note : There are 9 buttons with the same name, and I have tested changing one of them and give the particular name in controller, it didn't work either.) Please suggest me a solution.
<input name="btn_read" class="readbtn" value="Read More" /> There is no input type. You have to mention the type of input.
<input type="submit" name="btn_read" class="readbtn" value="Read More" />

PHP Trying to get string from a table cell with regular expressions

I have the following site and I want with regular expressions to get the text between the following tags
<td colspan="2" align="left" valign="top" bgcolor="#FBFAF4"> ..... </td>
I am trying with the following however it returns an empty array of $matches.
preg_match_all("/<td(.*) bgcolor=\"#FBFAF4\"\>(.*)\<\/td>/",$old_filecontents,$matches);
Which is the correct pattern for this?
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Exotiq - Ðñïúüíôá</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-7"> <link href="Styles.css" rel="stylesheet" type="text/css"> <link href="stylesheets/Styles.css" rel="stylesheet" type="text/css"> <script src="scripts/PopBox.js" type="text/javascript"></script> <script type="text/javascript"> popBoxWaitImage.src = "images/spinner40.gif"; popBoxRevertImage = "images/magminus.gif"; popBoxPopImage = "images/magplus.gif"; </script> <script type="text/javascript"> AC_FL_RunContent('codebase', 'http://download.macromedia.com/pub/shockwave/ cabs/flash/swflash.cab#version=9,0,28,0', 'width','675','height','445','title','Morpork', 'src','assets/flash/morepork','loop', 'false','quality','high','pluginspage', 'http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash', 'wmode','transparent','movie','assets/flash/morepork'); </script> </head> <body background="images/fonto2.jpg" topmargin="0"> <table width="948" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td><table width="948" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td width="24"> </td> <td height="150" colspan="3"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="900" height="150"> <param name="movie" value="flash/top02.swf"> <param name="quality" value="high"> <param name="wmode" value="transparent"> <embed src="flash/top02.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="900" height="150"></embed></object></td> <td width="24" height="150"> </td> </tr> <tr> <td height="31" colspan="5" valign="middle"> <div align="center"> <script src="menu/xaramenu.js"></script> <script Webstyle4 src="menu/menu_.js"></script> </div></td> </tr> <tr> <td width="24"> </td> <td width="200" valign="top" background="images/GreenFasa.jpg"> <br> <table width="180" border="0" align="center" cellpadding="0" cellspacing="1"> <tr> <td height="25" class="styles"> Makuti<br> <hr> </td> </tr> <tr> <td height="25" class="styles"> Fun Palm<br> <hr> </td> </tr> <tr> <td height="25" class="styles"> Alang-Alang<br> <hr> </td> </tr> <tr> <td height="25" class="styles"> Thatch<br> <hr> </td> </tr> <tr> <td height="25" class="styles"> <strong>Abaca</strong><br> <hr> </td> </tr> <tr> <td height="25" class="styles"> </td> </tr> </table></td> <td colspan="2" align="left" valign="top" bgcolor="#FBFAF4"> <div align="left"> <table width="680" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td width="600" height="40" class="titles">ÊáôáóêåõÝò - ÏìðñÝëåò - Abaca</td> <td width="50" align="right" valign="middle" class="titles"> <div align="right"><img src="images/uk-flag.jpg" width="30" height="17" border="0"></div></td> </tr> <tr> <td colspan="2" class="body"><p>Ç ïìðñÝëá <strong>Abaca</strong> Ýñ÷åôáé ùò Üîéïò áíôéêáôáóôÜôçò ôçò ïìðñÝëáò Rattan ðïõ åðß 15 ÷ñüíéá óôïëßæåé ôéò åëëçíéêÝò ðáñáëßåò. Ôï <strong>Abaca</strong> åßíáé Ýíá öõóéêü õëéêü ðéï <strong>áíèåêôéêü</strong> êáé ðéï üìïñöï áðü ôï Rattan. <br> Ðáñáäßäåôáé ìå <strong>îýëéíï êïñìü åìðïôéóìïý</strong> Ö8åê.<br> <br> </p> <table width="680" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="340" height="150" valign="middle"> <div align="left"><img src="images/Manufactures/Umbrelas/Abaca/AbacaUmbrela.jpg" width="328" height="500"></div></td> <td width="340" height="150" valign="bottom" class="body"> <table width="340" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="170" height="130"> <div align="center"><img src="images/Manufactures/Umbrelas/Abaca/1_Abaca02_s.jpg" width="152" height="101" class="PopBoxImageSmall" onclick="Pop (this,50,'PopBoxImageLarge');" title="ÌåãÝèõíóç" pbsrc="images/Manufactures/Umbrelas/Abaca/1_Abaca02.jpg" pbCaption="Abaca - ÏìðñÝëá ðáñáëßáò" popBoxCaptionBelow="true" /></div></td> <td width="170" height="130"> <div align="center"><img src="images/Manufactures/Umbrelas/Abaca/2_Abaca03_s.jpg" width="150" height="112" class="PopBoxImageSmall" onclick="Pop (this,50,'PopBoxImageLarge');" title="ÌåãÝèõíóç" pbsrc="images/Manufactures/Umbrelas/Abaca/2_Abaca03.jpg" pbCaption="Abaca - ÏìðñÝëá ðáñáëßáò" popBoxCaptionBelow="true" /></div></td> </tr> <tr> <td width="170" height="130"> <div align="center"><img src="images/Manufactures/Umbrelas/Abaca/3_Abaca01_s.jpg" width="150" height="112" class="PopBoxImageSmall" onclick="Pop (this,50,'PopBoxImageLarge');" title="ÌåãÝèõíóç" pbsrc="images/Manufactures/Umbrelas/Abaca/3_Abaca01.jpg" pbCaption="Abaca - ÏìðñÝëá ðáñáëßáò" popBoxCaptionBelow="true" /></div></td> <td width="170" height="130"> <div align="center"></div></td> </tr> <tr> <td width="170" height="130"> <div align="center"></div></td> <td width="170" height="130"> <div align="center"></div></td> </tr> <tr> <td width="170" height="130"> <div align="center"></div></td> <td width="170" height="130"> <div align="center"></div></td> </tr> </table></td> </tr> <tr> <td width="340" height="50" valign="top"> <p align="center"> </p></td> <td width="340" height="50" valign="top"> <div align="center" class="perigrafes">ÊëéêÜñåôáé ðÜíù óôéò öùôïãñáößåò ãéá ìåãÝèõíóç</div></td> </tr> <tr> <td width="340" valign="bottom"> <div align="center"> </div></td> <td width="340" valign="bottom"> <p align="center"> </p></td> </tr> <tr> <td width="340" valign="top"> <div align="center"></div></td> <td width="340" valign="top"> <p align="center"> </p></td> </tr> <tr> <td height="20" colspan="2" valign="top"> </td> </tr> </table></td> </tr> </table> <font color="#FFFFFF"></font></div></td> <td width="24" height="420"> </td> </tr> <tr> <td width="24"> </td> <td width="200"> </td> <td width="600"> </td> <td width="100"> </td> <td width="24"> </td> </tr> </table></td> </tr> <tr> <td height="22"><table width="900" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#007F3E"> <tr> <td height="25"> <div align="center" class="styles">All rights reserved ® Designed by CONTINENTAL ADVERTISING </div></td> </tr> </table></td> </tr> </table> <script type="text/javascript"> var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E")); </script> <script type="text/javascript"> try { var pageTracker = _gat._getTracker("UA-12742174-1"); pageTracker._trackPageview(); } catch(err) {}</script> </body> </html>
Given that the cell you're talking about contains HTML, another table in fact, you can't do traditional termination checking ... or you'll get the content between the cell opening and the first </td> you find. Plus '.' isn't multi-line friendly, so unless your cell opens and terminates on the same line, you'll get no matches.
I'd say don't use regular expressions for this. Try an XML parser.
If you were just getting plain text, that'd be fine, but because you're returning HTML which contains your terminator, you'll need to use a parser with some kind of DOM depth awareness ... ... or find a way to count terminators in regex.

Php HTML DOM parsing

<table width="100%" cellspacing="0" cellpadding="0" border="0" id="Table4">
<tbody>
<tr>
<td valign="top" class="tx-strong-dgrey">
<a class="anc-noul" href="http://www.example.com/catalog/proddetail.asp?logon=&langid=EN&sku_id=0665000FS10129471&catid=25653">
Apple 8GB 3rd Generation iPod Touch</a></td>
</tr>
<tr>
<td valign="top" class="element-spacer"/>
</tr>
<tr>
<td valign="top" class="tx-normal-grey">
Product detail
<a href="http://www.example.com/catalog/proddetail.asp?logon=&langid=EN&sku_id=0665000FS10129471&catid=25653">
More Info</a></td>
</tr>
<tr>
<td valign="top" class="element-spacer"/>
</tr>
<tr>
<td valign="top" class="tx-normal-red">
<span class="tx-strong-dgrey">Price:</span>
$189.99</td>
</tr>
<tr>
<td valign="top">You save: $9.00 after instant savings</td>
</tr>
<tr>
<td valign="top" class="element-spacer"/>
</tr>
<tr>
<td valign="top" class="tx-normal-grey">
<a href="http://www.example.com/catalog/subclass.asp?catid=25653&logon=&langid=EN">
View similar products</a>
<a href="http://www.example.com/catalog/mfr.asp?man=Apple&catid=19&logon=&langid=EN">
View similar products with same brand</a>
</td></tr>
<tr>
<td valign="top" class="element-spacer"/>
</tr>
</tbody>
</table>
I want to be able to get the $189.99.
echo $ret[0]->find('tr', 4)->plaintext;
This outputs: 'Price: $189.99'
I just need $189.99, not 'Price:'
$exp = explode(":", $ret[0]->find('tr', 4)->plaintext);
$price =$exp[1];

Categories