PHP intercepts the class and instance of the content between the specified characters (including transcoding, filtering HTML, etc.).
half a programmer like me, basically rely on Baidu. Basically, on the basis of the valuable experience of our predecessors, we need to integrate and modify them according to current needs. So thank you first. Statement: knowledge sources do not represent original sources, but represent the knowledge that I find from that place. The first part, the basic knowledge point
1, a PHP intercept the class of the string of the string between the specified strings; php
class get_c_str {
var. ($str, $start_str, $end_str) {
$this-.gt; STR = $str;
$this-.gt; start_str = $start_str; End_str;
}
}
praise expert, so much with a function a few lines of code to engage in Sure. At the same time, thank you again for the dedication.
the use of the above classes:
.lt; php
$get_c_str = new get_c_str;
echo $get_c_str -.gt; get_str. A string that can be processed before it can be a variable that contains string values. The comma is the HTML tag retained during filtering. If it is not specified, all the HTML tags in the processed string will be completely cleared, leaving only the text. The processing of
3 and the content (such as web page) that is captured is inconsistent with the need to display.
if the content is not consistent with the coding of the page, it will cause confusion, and it will be very hard for a long time. The following methods are found:
knowledge source: http://hi.baidu.com/swhl010515/blog/item/033ae6e54a52ca22b838200d.html
a, converting GBK coded strings to UTF-8 coded string
Php code
.lt;? PHP
header. Ncoding (.Quot; you are my good friend.Quot;.Quot; UTF-8.quot;.Quot; GBK.quot;);
.lt; The UTF-8 coded string is converted into a GB2312 coded string
Php code
.Gt;
>.Gt;
c, convert the entire page to
this method applies to all coding environments. NCR (Numeric character reference, such as "Chinese characters" will be converted to ".Amp; amp; #27721;.Amp; amp; #23383;" in the form of a character set other than the first 128 characters (the display character) to indicate that such a code can be displayed in an arbitrary coding environment. The
method is to add the following three lines of code in the head of the PHP file: the
Php code
mb_internal_encoding (.Quot; gb2312.quot;); / / / / / / / / B2312.quot; / / / / / / / / GB2312 is your website's original encoding
mb_http_output (.Quot; HTML-ENTITIES.quot;);
ob_start ('mb_output_handler');
* Note: use mb_convert_encoding function to enable PHP extensions / > two, application instance / > this instance It is to grab some part of a web page and process it into a variable that can be invoked, or more in line with the format required.
.lt;?
/ / / / / / / / / / / / / / / / / / / / / base variable * to get the data source, can be a web page, a local text file and a web page
$file_name=.quot; http://www.pualin.com/fangfa/rjgz/1302272968.html.quot;;
/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / OS;
var $end_pos;
var $c_str_l;
var $contents;
function. ($this-.gt; start_str);
$this-.gt; end_pos = strpos ($this-.gt; STR, $this-.gt; end_str);
$this-.gt. >}
$file_handle = fopen (.Quot;.Quot; r.quot;);
while. Get_str ($sjb,'forecast.quot;.Gt;'margin-bottom');
/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / c_str Uot;.Quot; UTF-8.quot;);
echo $sjb;
?.gt;
summary: in the above instances, the $sjb variables that have been captured and processed directly are displayed directly. In practice, you can call this variable at CMS templates. In addition, CSS can also format the content in order to achieve better display effect.