PHP在标签之间获取字符串 [英] Php get string between tags

查看:90
本文介绍了PHP在标签之间获取字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个像这样的字符串,它是(Joomla所有视频插件)

I got a string like this which is (Joomla all video plugin)

{Vimeo}123456789{/Vimeo} 

其中123456789是可变的,我该如何提取呢? 我应该使用正则表达式吗?

where 123456789 is variable, how can I extract this? Should I use regex?

推荐答案

如果必须使用正则表达式,则可以使用以下技巧.

If you must use a regular expression, the following will do the trick.

$str = 'foo {Vimeo}123456789{/Vimeo} bar';
preg_match('~{Vimeo}([^{]*){/Vimeo}~i', $str, $match);
var_dump($match[1]); // string(9) "123456789"

这可能不仅仅是您要经历的事情,但这是避免正则表达式的一种方法.

This may be more than what you want to go through, but here is a way to avoid regex.

$str = 'foo {Vimeo}123456789{/Vimeo} bar';
$m = substr($str, strpos($str, '{Vimeo}')+7);
$m = substr($m, 0, strpos($m, '{/Vimeo}'));
var_dump($m); // string(9) "123456789"

这篇关于PHP在标签之间获取字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆