php extract article content image address regular expression

Source: Internet
Author: User
Keywords Network programming PHP tutorial
Tags address array content expression html http image name

<! doctype html public "- // w3c // dtd xhtml 1.0 transitional // en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns = "http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv = "content-type" content = "text / html; charset = gb2312" />
<title> php tutorial to extract article content image address regular expression </ title>
</ head>

<body>
<form id = "form1" name = "form1" method = "post" action = "">
<p>
<label for = "body"> </ label>
<textarea name = "body" id = "body" cols = "45" rows = "5"> </ textarea>
</ p>
<p>
<input type = "submit" name = "button" id = "button" value = "Submit" />
</ p>
</ form>
</ body>
</ html>
<?
if ($ _post)
{
$ body = $ _post ['body'];
preg_match_all (/ src | src) = ["| '|] {0,} ((. *). (gif | jpg | jpeg | png | bmp)) / isu", $ body, $ array);
if ($ array)
{
echo 'get the picture address';
print_r ($ array);
}
else
{
echo 'article content does not exist in the effective image address';
}
}

/ * Test input

Here is www.jzread.com to provide you with a regular access to the contents of the article in the picture address code is as follows
<img src = / get_pic / 2010/03 / 20100811004403298.gif />
fdsafdsafsa
result:
Get image address array
(
[0] => array
(
[0] => src = / get_pic / 2010/03 / 20100811004403298.gif
)

[1] => array
(
[0] => src
)

[2] => array
(
[0] => /get_pic/2010/03/20100811004403298.gif
)

[3] => array
(
[0] => http://www.jzread.com/a
)

[4] => array
(
[0] => gif
)

)
?>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.