php用正则表达式截取字符

WBOY
WBOYオリジナル
2016-06-13 10:01:272527ブラウズ

php用正则表达式截取字符【求助】
哪位高手帮忙看看:我想从下面的代码中提取
{dede:field name='keywords'}{/dede:field}
{dede:field name='description'}{/dede:field}
{dede:field name='title'}http://down.sucai.com/fonts/soft/071130/1_071204075903.rar{/dede:field}
{dede:field name='writer'}{/dede:field}
{dede:field name='source'}{/dede:field}
{dede:field name='body'}{/dede:field}
{dede:field name='pubdate'}{/dede:field}
{dede:field name='litpic'}/uploads/allimg/c100112/12632b9420Z-412413.jpg{/dede:field}
这个
http://down.sucai.com/fonts/soft/071130/1_071204075903.rar

/uploads/allimg/c100112/12632b9420Z-412413.jpg
正则应该怎么来写呢

------解决方案--------------------

PHP code
 <br> $str =   {dede:field name='keywords'}{/dede:field} <br> {dede:field name='description'}{/dede:field} <br> {dede:field name='title'}http://down.sucai.com/fonts/soft/071130/1_071204075903.rar{/dede:field} <br> {dede:field name='writer'}{/dede:field} <br> {dede:field name='source'}{/dede:field} <br> {dede:field name='body'}{/dede:field} <br> {dede:field name='pubdate'}{/dede:field} <br> {dede:field name='litpic'}/uploads/allimg/c100112/12632b9420Z-412413.jpg{/dede:field} <br> EOF; <br>  <br> preg_match_all("#name='(title|litpic)'\}(.*)\{#U",$str,$matches); <br>  <br> print_r($matches); <br> 

------解决方案--------------------
$s = {dede:field name='keywords'}{/dede:field} 
{dede:field name='description'}{/dede:field} 
{dede:field name='title'}http://down.sucai.com/fonts/soft/071130/1_071204075903.rar{/dede:field} 
{dede:field name='writer'}{/dede:field} 
{dede:field name='source'}{/dede:field} 
{dede:field name='body'}{/dede:field} 
{dede:field name='pubdate'}{/dede:field} 
{dede:field name='litpic'}/uploads/allimg/c100112/12632b9420Z-412413.jpg{/dede:field} 
HTML;

$p = '#}(.+){#';

preg_match_all($p, $s, $r);
print_r($r[1]);


Array
(
[0] => http://down.sucai.com/fonts/soft/071130/1_071204075903.rar
[1] => /uploads/allimg/c100112/12632b9420Z-412413.jpg
)
声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。