There is a standard design:

$temperature_find="<div class=\"report_text temperature\" style=\"color:#A1B2C3;\">"; // далее. $str_pos = strripos($site_contents, $temperature_find); 

Found the position of the expression in the text. Good.
But he got into a stupor, because the color:#A1B2C3 parameter color:#A1B2C3 dynamic. He is constantly changing.

How to use regular expressions to upgrade this construct?


UPD - I didn’t train my brain, did this:

 $temperature_find="<div class=\"report_text temperature\""; $str_pos = strripos($site_contents, $temperature_find); $code_for_out = substr($site_contents, $str_pos+60, 2); 

I feel that the code from the category 1 + 1 + 1 + 1 = 4, although it would be more correct to 2² = 4

  • But what do you want to do with it? - teran
  • @teran; Next, like this: $str_pos_end = strripos($site_contents, $temperature_find_end); $code_out_data = substr($site_contents, $str_pos, ($str_pos_end-$str_pos)); $str_pos_end = strripos($site_contents, $temperature_find_end); $code_out_data = substr($site_contents, $str_pos, ($str_pos_end-$str_pos)); - I_CaR
  • Can I speak Russian? :) do you need to get the color value simply, or replace it, or what? - teran
  • In the body of Yulok <div>, which I am looking for, and which has color, information is stored. Here I also want to pull out it. Not the color of the div, but what surrounds the div. krasnovosti.ru/soft/temperatura/… - I_CaR
  • one
    arm yourself with tools that work with the HTML DOM. search for substrings and regulars for this problem is not particularly needed. simple html dom, etc. - teran

1 answer 1

Prompted about preg_match . Implementation:

 preg_match("/<div class=\"report_text temperature\" style=\"color:(#[a-zA-Z0-9]{6});\">/", $site_contents, $matches); $str_pos = strripos($site_contents, $matches[0]); $code_for_out = substr($site_contents, $str_pos+60, 2);