The following uses preg_match to give two examples: one is to obtain the content of the specified area, and the other is to obtain the url address in the content.
The following uses preg_match to give two examples: one is to obtain the content of the specified area, and the other is to obtain the url address in the content.
*/
$string="example:
this is a test
"; //Define string
$pattern="|<[^>]+>(.*)[^>]+>|u"; //Define regular expression pattern
/*The meaning of this matching pattern is: starting with "<" followed by 1 to more characters that are not ">" and ending content; ".*" in the sub-pattern represents 0 to more any characters. In addition, it starts with "<" followed by one or more characters that are not ">" plus the ">" symbol. */
preg_match_all($pattern,$string,$out,preg_pattern_order); //Perform preg_mathc_all processing
echo $out[0][0];
echo ",";
echo $out[0][1];
echo "
";
echo $out[1][0];
echo ",";
echo $out[1][1];
//Example 2
//The following code is used to extract the domain name
$http="http://www.bKjia.c0m"; //Define URL
preg_match("/^(http://)?([^/]+)/i",$http,$matches); //Regular expression matching
$host=$matches[2]; //Assign the result array elements to the variable
preg_match("/[^./]+.[^./]+$/",$host,$matches); //Regular expression matching
echo "domain name is:{$matches[0]}n"; //Output result domain name
http://www.bkjia.com/PHPjc/631356.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/631356.htmlTechArticleThe following uses preg_match to give two examples. One is to obtain the content of the specified area, and the other is to obtain the url address in the content. Below are two examples using preg_match. One is to obtain the specified area...