|
|
|
| Добрый день.
Выделяем таблицу с характеристиками:
foreach ($fly->find('div table[class="options"]') as $table_div)
{
$table_str = $table_div;
$search_tr = "<tr>";
$if_table = stripos($table_str, $search_tr); // Ищем тег <tr>
// Если найден тег <tr> выводим таблицу
if($if_table)
{
$prod_table = $table_str;
//echo $prod_table."<br><br>\n\n";
print_r($prod_table);
echo "(".gettype($prod_table).")"."<br>";
}
else
{}
}
|
Делаем запрос в БД:
$product_list_str='insert into product_list(product_name,product_price,product_s_desc,product_full_image,product_thumb_image,product_desc) values(\''.cp1251_to_utf8($prod_name).'\',\''.$prod_price.'\',\''.cp1251_to_utf8(addslashes($prod_s_desc)).'\',\''.$full_img.'\',\''.$thumb_img.'\',\''.cp1251_to_utf8(addslashes($prod_table)).'\')';
mysql_query($product_list_str);
|
Импортировать в БД не получается т.к. тип $prod_table - Object
Команда print_r($prod_table); выдает непонятно что(наверное объект DOM):
simple_html_dom_node Object ( [nodetype] => 1 [tag] => table [attr] => Array ( [class] => options ) [children] => Array ( [0] => simple_html_dom_node Object ( [nodetype] => 1 [tag] => tbody [attr] => Array ( ) [children] => Array ( [0] => simple_html_dom_node Object ( [nodetype] => 1 [tag] => tr [attr] => Array ( ) [children] => Array ( [0] => simple_html_dom_node Object ( [nodetype] => 1 [tag] => td [attr] => Array ( [colspan] => 2 [align] => center ) [children] => Array ( [0] => simple_html_dom_node Object ( [nodetype] => 1 [tag] => nobr [attr] => Array ( ) [children] => Array ( [0] => simple_html_dom_node Object ( [nodetype] => 1 [tag] => b [attr] => Array ( ) [children] => Array ( [0] => simple_html_dom_node Object ( [nodetype] => 1 [tag] => u [attr] => Array ( ) [children] =>
|
Как мне этот хаос преобразовать в строку, подходящую для внесения в БД?:
<table class="options">
<tbody>
<tr><td colspan="2" align="center"><nobr><b><u>Общие характеристики:</u></b></nobr></td></tr>
<tr>
<th scope="col" width=50%>Производитель</th>
<td scope="col" width=50%>Samsung </td>
</tr>
<tr>
<th scope="col" width=50%>Официальное название</th>
<td scope="col" width=50%>Ноутбук R528 (NP-R528-DB01UA) Black [Samsung] </td>
</tr>
<tr>
<th scope="col" width=50%>Код</th>
<td scope="col" width=50%>NP-R528-DB01UA </td>
</tr>
<tr><td colspan="2" align="center"><nobr><b><u>Ссылки:</u></b></nobr></td></tr>
<tr>
<th scope="col" width=50%>Сайт производителя</th>
<td scope="col" width=50%><a href="http://www.samsung.com" title="http://www.samsung.com" target="_blank">Ссылка</a> </td>
</tr>
</tbody>
</table>
|
Выводит ошибку:
Notice: Trying to get property of non-object in C:\wamp\www\php\simple_html_dom.php on line 181
Notice: Trying to get property of non-object in C:\wamp\www\php\simple_html_dom.php on line 188
Fatal error: Call to a member function makeup() on a non-object in C:\wamp\www\php\simple_html_dom.php on line 188
|
| |
|
|
|
|
|
|
|
для: A1exander
(03.10.2010 в 19:18)
| | Решил :)
Надо сделать так:
foreach ($fly->find('div table[class="options"]') as $table_div)
{
$table_str = $table_div->outertext;
$search_tr = "<tr>";
$if_table = stripos($table_str, $search_tr); // Ищем тег <tr>
// Если найден тег <tr> выводим таблицу
if($if_table)
{
$prod_table = $table_str;
//$prod_table = $prod_table_dim;
echo $prod_table."<br><br>\n\n";
//print_r($prod_table);
echo "(".gettype($prod_table).")"."<br>";
}
else
{}
}
|
Выделено жирным. Тогда выделяемое становится именно строкой. | |
|
|
|