欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

php用正则表达式截取字符

程序员文章站 2022-05-16 19:28:11
...
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
 
$str = {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}
EOF;

preg_match_all("#name='(title|litpic)'\}(.*)\{#U",$str,$matches);

print_r($matches);

------解决方案--------------------
$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
)
php用正则表达式截取字符

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。

相关文章

相关视频