Re: Text between two tags

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Maybe just treat it like XML and use PHP's XML parsing routines.  Should work pretty good but maybe someone else has a better way of handling it. (code below)

-TG


// $string - contains your HTML string

$innerText = "";

$_XML_PARSER = xml_parser_create();
xml_set_element_handler($_XML_PARSER,'xml_open_element_function','xml_close_element_function');
xml_set_character_data_handler($_XML_PARSER,'xml_handle_character_data');
xml_parse($_XML_PARSER,$string,strlen($string));
xml_parser_free($_XML_PARSER);

echo $innerText;

function xml_response_open_element_function($p, $element, $attributes){
  global $grabInnerText;

  if (strtolower($element) == "td" AND $attributes['class'] == "yfnc_tabledata1") {
    $grabInnerText = true;
  } else {
    $grabInnerText = false;
  }
}

function xml_response_close_element_function($p, $element){
  global $grabInnerText;

  // Probably unnecessary?
  $grabInnerText = false;
}

function xml_response_handle_character_data_pdf($p, $cdata){
  global $grabInnerText;
  global $innerText;

  if ($grabInnerText) {
    $innerText .= $cdata;
  }
}


= = = Original message = = =

Hello
I'm trying to extract some text between two tags:

Example
I have this string :
$text='<td></td>
<td align="right" class="yfnc_tabledata3"></td>
<td></td>
<td align="right" class="yfnc_tabledata2"></td>
<td></td>
<td align="right" class="yfnc_tabledata1">1234</td>
<td></td> <td></td> <td></td> <td align="right" class="yfnc_tabledata5"></td> ';

And I want to retrieve the number 1234 between <td align="right"
class="yfnc_tabledata1"> and </td>
Any idea??

Normmy.


___________________________________________________________
Sent by ePrompter, the premier email notification software.
Free download at http://www.ePrompter.com.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux