Regex pattern for preg

Possible Duplicate:
How to extract img src, title and alt from html using php?

I want to allow users upload images to uploads/tmp folder for future use in their posts. 1. User uploads several images to 'uploads/tmp/' Here is his text:

Some text with img tags:
    1. <img src="http://site.com/uploads/tmp/d272b2d4.jpg">
    2. <img src="http://www.site.com/uploads/tmp/132784ca.jpg">
    3. <img src="www.site.com/uploads/tmp/e08b0bc8.jpg">
    4. <img src="site.com/uploads/tmp/f40ba84c.jpg">

I want to get those filenames from src property and move files to desired folder and then to replace images to:

1. <img src="http://site.com/uploads/posts/user/d272b2d4.jpg">
2. <img src="http://www.site.com/uploads/posts/user/132784ca.jpg">
3. <img src="www.site.com/uploads/tmp/posts/user/e08b0bc8.jpg">
4. <img src="site.com/uploads/tmp/posts/user/f40ba84c.jpg">

So the problem is I can't create the pattern for getting and replacing filenames in src and would be grateful for any help. I'm using PHP.


使用:

preg_match_all( '/(?:src=")((?:http(?:s|)://|)(?:www.|)site.com/uploads/tmp/[a-z0-9]+.jpg(?:")/is', $subject, $matches);

var_dump( $matches );

This should get all the sources if you are passing more then one img tags to it in the $subject .

preg_match_all( '/(?:src=")(.+)(?:")/i', $subject, $matches);

Test $matches for matches

echo '<pre>'.print_r($matches,true).'</pre>';
链接地址: http://www.djcxy.com/p/69828.html

上一篇: PHP解析错误:语法错误,意外的T

下一篇: preg的正则表达式模式